2 Copyright 2003, CyberTAN Inc. All Rights Reserved
4 This is UNPUBLISHED PROPRIETARY SOURCE CODE of CyberTAN Inc.
5 the contents of this file may not be disclosed to third parties,
6 copied or duplicated in any form without the prior written
7 permission of CyberTAN Inc.
9 This software should be used as a reference only, and it not
10 intended for production use!
12 THIS SOFTWARE IS OFFERED "AS IS", AND CYBERTAN GRANTS NO WARRANTIES OF ANY
13 KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. CYBERTAN
14 SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
15 FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE
27 #include <sys/socket.h>
28 #include <netinet/in.h>
30 #include <sys/ioctl.h>
31 #include <sys/sysinfo.h>
37 #include <net/route.h>
40 #include <linux/if_ether.h>
41 #include <linux/sockios.h>
46 // -----------------------------------------------------------------------------
49 #if 0 // beyond here are obsolete functions
51 struct wl_assoc_mac
*get_wl_assoc_mac(int *c
)
54 struct wl_assoc_mac
*wlmac
;
62 if ((f
= popen("wl assoclist", "r")) != NULL
) {
63 // assoclist 00:11:22:33:44:55
64 while ((fgets(line
, sizeof(line
), f
)) != NULL
) {
65 if (sscanf(line
,"assoclist %17s", mac
) != 1) continue;
67 wlmac
= realloc(wlmac
, sizeof(wlmac
[0]) * (count
+ 1));
73 memset(&wlmac
[count
], 0, sizeof(wlmac
[0]));
74 strlcpy(wlmac
[count
].mac
, mac
, sizeof(wlmac
[0].mac
));
88 show_hw_type(int type)
90 if(type == BCM4702_CHIP)
91 cprintf("The chipset is BCM4702\n");
92 else if(type == BCM5325E_CHIP)
93 cprintf("The chipset is BCM4712L + BCM5325E\n");
94 else if(type == BCM4704_BCM5325F_CHIP)
95 cprintf("The chipset is BCM4704 + BCM5325F\n");
96 else if(type == BCM5352E_CHIP)
97 cprintf("The chipset is BCM5352E\n");
98 else if(type == BCM4712_CHIP)
99 cprintf("The chipset is BCM4712 + ADMtek\n");
101 cprintf("The chipset is not defined\n");
106 #define SIOCGMIIREG 0x8948 /* Read MII PHY register. */
107 #define SIOCSMIIREG 0x8949 /* Write MII PHY register. */
109 struct mii_ioctl_data
{
110 unsigned short phy_id
;
111 unsigned short reg_num
;
112 unsigned short val_in
;
113 unsigned short val_out
;
117 unsigned long get_register_value(unsigned short id
, unsigned short num
)
120 struct mii_ioctl_data stats
;
127 ifr
.ifr_data
= (void *)&stats
;
129 sys_netdev_ioctl(AF_INET
, -1, get_device_name(), SIOCGMIIREG
, &ifr
);
131 return ((stats
.val_in
<< 16) | stats
.val_out
);
134 // xref: set_register_value
135 static char *get_device_name(void)
137 switch (check_hw_type()){
139 case BCM4704_BCM5325F_CHIP
:
149 // xref: sys_netdev_ioctl
150 static int sockets_open(int domain
, int type
, int protocol
)
152 int fd
= socket(domain
, type
, protocol
);
154 cprintf("sockets_open: no usable address was found.\n");
158 // xref: set_register_value
159 static int sys_netdev_ioctl(int family
, int socket
, char *if_name
, int cmd
, struct ifreq
*ifr
)
163 if ((s
= socket
) < 0) {
164 if ((s
= sockets_open(family
, family
== AF_PACKET
? SOCK_PACKET
: SOCK_DGRAM
,
165 family
== AF_PACKET
? htons(ETH_P_ALL
) : 0)) < 0) {
166 cprintf("sys_netdev_ioctl: failed\n");
170 strcpy(ifr
->ifr_name
, if_name
);
171 rc
= ioctl(s
, cmd
, ifr
);
172 if (socket
< 0) close(s
);
177 int set_register_value(unsigned short port_addr
, unsigned short option_content
)
180 struct mii_ioctl_data stats
;
182 stats
.phy_id
= port_addr
;
183 stats
.val_in
= option_content
;
185 ifr
.ifr_data
= (void *)&stats
;
187 if (sys_netdev_ioctl(AF_INET
, -1, get_device_name(), SIOCSMIIREG
, &ifr
) < 0)