Tomato 1.28
[tomato.git] / release / src / router / shared / wl_linux.c
blobf7180d2d778b1d2edb1468c2998d5f0ee0f0de00
1 /*
2 * Wireless network adapter utilities (linux-specific)
4 * Copyright 2005, 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.
12 * $Id: wl_linux.c,v 1.1.1.8 2005/03/07 07:31:20 kanki Exp $
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <sys/ioctl.h>
20 #include <net/if.h>
22 typedef u_int64_t u64;
23 typedef u_int32_t u32;
24 typedef u_int16_t u16;
25 typedef u_int8_t u8;
26 #include <linux/sockios.h>
27 #include <linux/ethtool.h>
29 #include <typedefs.h>
30 #include <wlioctl.h>
31 #include <wlutils.h>
33 // xref: nas,wlconf,httpd,rc,
34 int wl_ioctl(char *name, int cmd, void *buf, int len)
36 struct ifreq ifr;
37 wl_ioctl_t ioc;
38 int ret = 0;
39 int s;
41 /* open socket to kernel */
42 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
43 perror("socket");
44 return errno;
47 /* do it */
48 ioc.cmd = cmd;
49 ioc.buf = buf;
50 ioc.len = len;
52 /* initializing the remaining fields */
53 ioc.set = FALSE;
54 ioc.used = 0;
55 ioc.needed = 0;
57 strncpy(ifr.ifr_name, name, IFNAMSIZ);
58 ifr.ifr_data = (caddr_t) &ioc;
59 ret = ioctl(s, SIOCDEVPRIVATE, &ifr);
61 if ((ret = ioctl(s, SIOCDEVPRIVATE, &ifr)) < 0)
62 if (cmd != WLC_GET_MAGIC)
63 perror(ifr.ifr_name);
65 /* cleanup */
66 close(s);
67 return ret;
70 // xref: wl.c:wl_probe()
71 int wl_get_dev_type(char *name, void *buf, int len)
73 int s;
74 int ret;
75 struct ifreq ifr;
76 struct ethtool_drvinfo info;
78 /* open socket to kernel */
79 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
80 perror("socket");
81 return -1;
84 /* get device type */
85 memset(&info, 0, sizeof(info));
86 info.cmd = ETHTOOL_GDRVINFO;
87 ifr.ifr_data = (caddr_t)&info;
88 strlcpy(ifr.ifr_name, name, IFNAMSIZ);
89 if ((ret = ioctl(s, SIOCETHTOOL, &ifr)) < 0) {
90 *(char *)buf = '\0';
92 else {
93 strlcpy(buf, info.driver, len);
96 close(s);
97 return ret;
100 // xref: nas,wlconf,
101 int wl_hwaddr(char *name, unsigned char *hwaddr)
103 struct ifreq ifr;
104 int ret = 0;
105 int s;
107 /* open socket to kernel */
108 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
109 perror("socket");
110 return errno;
113 /* do it */
114 strlcpy(ifr.ifr_name, name, IFNAMSIZ);
115 if ((ret = ioctl(s, SIOCGIFHWADDR, &ifr)) == 0)
116 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
118 /* cleanup */
119 close(s);
120 return ret;