Extended MOTD with GUI
[tomato.git] / release / src / router / shared / wl_linux.c
blobed5bb8b0207cf9edb96fb32e591c488893ef95d7
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/types.h>
27 #include <linux/sockios.h>
28 #include <linux/ethtool.h>
30 #include <typedefs.h>
31 #include <wlioctl.h>
32 #include <wlutils.h>
34 // xref: nas,wlconf,httpd,rc,
35 int wl_ioctl(char *name, int cmd, void *buf, int len)
37 struct ifreq ifr;
38 wl_ioctl_t ioc;
39 int ret = 0;
40 int s;
42 /* open socket to kernel */
43 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
44 perror("socket");
45 return errno;
48 /* do it */
49 ioc.cmd = cmd;
50 ioc.buf = buf;
51 ioc.len = len;
53 /* initializing the remaining fields */
54 ioc.set = FALSE;
55 ioc.used = 0;
56 ioc.needed = 0;
58 strncpy(ifr.ifr_name, name, IFNAMSIZ);
59 ifr.ifr_data = (caddr_t) &ioc;
60 ret = ioctl(s, SIOCDEVPRIVATE, &ifr);
62 if ((ret = ioctl(s, SIOCDEVPRIVATE, &ifr)) < 0)
63 if (cmd != WLC_GET_MAGIC)
64 perror(ifr.ifr_name);
66 /* cleanup */
67 close(s);
68 return ret;
71 // xref: wl.c:wl_probe()
72 int wl_get_dev_type(char *name, void *buf, int len)
74 int s;
75 int ret;
76 struct ifreq ifr;
77 struct ethtool_drvinfo info;
79 /* open socket to kernel */
80 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
81 perror("socket");
82 return -1;
85 /* get device type */
86 memset(&info, 0, sizeof(info));
87 info.cmd = ETHTOOL_GDRVINFO;
88 ifr.ifr_data = (caddr_t)&info;
89 strlcpy(ifr.ifr_name, name, IFNAMSIZ);
90 if ((ret = ioctl(s, SIOCETHTOOL, &ifr)) < 0) {
91 *(char *)buf = '\0';
93 else {
94 strlcpy(buf, info.driver, len);
97 close(s);
98 return ret;
101 // xref: nas,wlconf,
102 int wl_hwaddr(char *name, unsigned char *hwaddr)
104 struct ifreq ifr;
105 int ret = 0;
106 int s;
108 /* open socket to kernel */
109 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
110 perror("socket");
111 return errno;
114 /* do it */
115 strlcpy(ifr.ifr_name, name, IFNAMSIZ);
116 if ((ret = ioctl(s, SIOCGIFHWADDR, &ifr)) == 0)
117 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
119 /* cleanup */
120 close(s);
121 return ret;