Add net-snmp package
[openwrt.git] / package / openwrt / libshared / wl.c
1 /*
2 * Wireless network adapter utilities
3 *
4 * Copyright 2004, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 *
12 * $Id$
13 */
14 #include <string.h>
15
16 #include <typedefs.h>
17 #include <wlutils.h>
18
19 int
20 wl_probe(char *name)
21 {
22 int ret, val;
23
24 /* Check interface */
25 if ((ret = wl_ioctl(name, WLC_GET_MAGIC, &val, sizeof(val))))
26 return ret;
27 if (val != WLC_IOCTL_MAGIC)
28 return -1;
29 if ((ret = wl_ioctl(name, WLC_GET_VERSION, &val, sizeof(val))))
30 return ret;
31 if (val > WLC_IOCTL_VERSION)
32 return -1;
33
34 return ret;
35 }
36
37 int
38 wl_set_val(char *name, char *var, void *val, int len)
39 {
40 char buf[128];
41 int buf_len;
42
43 /* check for overflow */
44 if ((buf_len = strlen(var)) + 1 + len > sizeof(buf))
45 return -1;
46
47 strcpy(buf, var);
48 buf_len += 1;
49
50 /* append int value onto the end of the name string */
51 memcpy(&buf[buf_len], val, len);
52 buf_len += len;
53
54 return wl_ioctl(name, WLC_SET_VAR, buf, buf_len);
55 }
56
57 int
58 wl_get_val(char *name, char *var, void *val, int len)
59 {
60 char buf[128];
61 int ret;
62
63 /* check for overflow */
64 if (strlen(var) + 1 > sizeof(buf) || len > sizeof(buf))
65 return -1;
66
67 strcpy(buf, var);
68 if ((ret = wl_ioctl(name, WLC_GET_VAR, buf, sizeof(buf))))
69 return ret;
70
71 memcpy(val, buf, len);
72 return 0;
73 }
74
75 int
76 wl_set_int(char *name, char *var, int val)
77 {
78 return wl_set_val(name, var, &val, sizeof(val));
79 }
80
81 int
82 wl_get_int(char *name, char *var, int *val)
83 {
84 return wl_get_val(name, var, val, sizeof(*val));
85 }
86
This page took 0.049003 seconds and 5 git commands to generate.