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: wl.c,v 1.1.1.1 2008/10/15 03:31:22 james26_jang Exp $
13 */
14#include <string.h>
15#include <stdio.h>
16#include <unistd.h>
17#include <errno.h>
18#include <sys/ioctl.h>
19#include <net/if.h>
20
21#include <typedefs.h>
22#include <wlutils.h>
23
24int
25wl_probe(char *name)
26{
27	int ret, val;
28
29#if defined(linux)
30	char buf[DEV_TYPE_LEN];
31	if ((ret = wl_get_dev_type(name, buf, DEV_TYPE_LEN)) < 0)
32		return ret;
33	/* Check interface */
34	if (strncmp(buf, "wl", 2))
35		return -1;
36#else
37	/* Check interface */
38	if ((ret = wl_ioctl(name, WLC_GET_MAGIC, &val, sizeof(val))))
39		return ret;
40#endif
41	if ((ret = wl_ioctl(name, WLC_GET_VERSION, &val, sizeof(val))))
42		return ret;
43	if (val > WLC_IOCTL_VERSION)
44		return -1;
45
46	return ret;
47}
48
49int
50wl_set_val(char *name, char *var, void *val, int len)
51{
52	char buf[WLC_IOCTL_SMLEN];
53	int buf_len;
54
55	/* check for overflow */
56	if ((buf_len = strlen(var)) + 1 + len > sizeof(buf))
57		return -1;
58
59	strcpy(buf, var);
60	buf_len += 1;
61
62	/* append int value onto the end of the name string */
63	memcpy(&buf[buf_len], val, len);
64	buf_len += len;
65
66	return wl_ioctl(name, WLC_SET_VAR, buf, buf_len);
67}
68
69int
70wl_get_val(char *name, char *var, void *val, int len)
71{
72	char buf[WLC_IOCTL_SMLEN];
73	int ret;
74
75	/* check for overflow */
76	if (strlen(var) + 1 > sizeof(buf) || len > sizeof(buf))
77		return -1;
78
79	strcpy(buf, var);
80	if ((ret = wl_ioctl(name, WLC_GET_VAR, buf, sizeof(buf))))
81		return ret;
82
83	memcpy(val, buf, len);
84	return 0;
85}
86
87int
88wl_set_int(char *name, char *var, int val)
89{
90	return wl_set_val(name, var, &val, sizeof(val));
91}
92
93int
94wl_get_int(char *name, char *var, int *val)
95{
96	return wl_get_val(name, var, val, sizeof(*val));
97}
98
99