source: src/router/services/networking/mssid.c @ 29281

Last change on this file since 29281 was 29281, checked in by brainslayer, 16 months ago

fix some wrong parameters. thx kryptex

File size: 3.7 KB
Line 
1/*
2 * mssid.c
3 *
4 * Copyright (C) 2005 - 2006 Sebastian Gottschall <gottschall@dd-wrt.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 *
20 * $Id:
21 */
22
23#include <ctype.h>
24#include <string.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <bcmnvram.h>
28#include <bcmutils.h>
29#include <shutils.h>
30#include "libbridge.h"
31#include <net/if.h>
32#include <netinet/in.h>
33#include <arpa/inet.h>
34#include <net/if_arp.h>
35#include <linux/sockios.h>
36#include <wlutils.h>
37#include <services.h>
38
39#define IFUP (IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST)
40
41void config_macs(char *wlifname)        // reconfigure macs which
42                                                // should fix the corerev 5
43                                                // and 7 problem
44{
45        int unit = get_wl_instance(wlifname);
46        char *vifs = nvram_nget("wl%d_vifs", unit);
47        char *mbss = nvram_nget("wl%d_mbss", unit);
48        char *next;
49        char var[80];
50
51        if (!strcmp(mbss, "0") || nvram_nmatch("apsta", "wl%d_mode", unit) || nvram_nmatch("ap", "wl%d_mode", unit)) {
52                if (vifs != NULL) {
53                        foreach(var, vifs, next) {
54                                eval("ifconfig", var, "down");
55                                eval("wl", "-i", var, "down");
56                                eval("wl", "-i", var, "cur_etheraddr", nvram_nget("%s_hwaddr", var));
57                                fprintf(stderr, "Setting %s BSSID:  %s \n", var, nvram_nget("%s_hwaddr", var));
58                                eval("wl", "-i", var, "bssid", nvram_nget("%s_hwaddr", var));
59                                eval("wl", "-i", var, "up");
60                                eval("ifconfig", var, "up");
61                        }
62                }
63        }
64}
65
66void do_mssid(char *wlifname)
67{
68        // bridge the virtual interfaces too
69        struct ifreq ifr;
70        int s;
71        char *next;
72        char var[80];
73        char *vifs = nvram_nget("wl%d_vifs", get_wl_instance(wlifname));
74        char tmp[256];
75        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
76                return;
77        if (vifs != NULL)
78                foreach(var, vifs, next) {
79                ether_atoe(nvram_nget("%s_hwaddr", var), ifr.ifr_hwaddr.sa_data);
80                strncpy(ifr.ifr_name, var, IFNAMSIZ);
81                ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
82                if (!nvram_nmatch("0", "%s_bridged", var)) {
83                        // ifconfig (var, IFUP, NULL, NULL);
84                        eval("ifconfig", var, "down");
85                        ioctl(s, SIOCSIFHWADDR, &ifr);
86                        eval("ifconfig", var, "up");
87                        br_add_interface(getBridge(var, tmp), var);
88                } else {
89                        eval("ifconfig", var, "down");
90                        ioctl(s, SIOCSIFHWADDR, &ifr);
91                        eval("ifconfig", var, "up");
92                        ifconfig(var, IFUP, nvram_nget("%s_ipaddr", var), nvram_nget("%s_netmask", var));
93                }
94                }
95        close(s);
96}
97
98#if !defined(HAVE_RT2880) && !defined(HAVE_RT61) && !defined(HAVE_MADWIFI)
99
100void set_vifsmac(char *base)    // corrects hwaddr and bssid assignment
101{
102        struct ifreq ifr;
103        int s;
104        char *next;
105        char var[80];
106        char mac[80];
107        char *vifs = nvram_nget("%s_vifs", base);
108
109        if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
110                return;
111        if (vifs != NULL) {
112                foreach(var, vifs, next) {
113                        eval("ifconfig", var, "down");
114                        wl_getbssid(var, mac);
115                        ether_atoe(mac, ifr.ifr_hwaddr.sa_data);
116                        ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
117                        strncpy(ifr.ifr_name, var, IFNAMSIZ);
118                        ioctl(s, SIOCSIFHWADDR, &ifr);
119                }
120        }
121        close(s);
122}
123
124void start_vifsmac(void)
125{
126        int cnt = get_wl_instances();
127        int c;
128        char name[32];
129
130        for (c = 0; c < cnt; c++) {
131                sprintf(name, "wl%d", c);
132                set_vifsmac(name);
133        }
134}
135#endif
Note: See TracBrowser for help on using the repository browser.