Changeset 10677


Ignore:
Timestamp:
10/28/08 22:31:27 (5 years ago)
Author:
BrainSlayer
Message:

madwifi support for wiviz2

Location:
src/router/wiviz2
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/router/wiviz2/Makefile

    r10676 r10677  
    2121CCOPTS  += -I$(SRCBASE)/include.v23 -L../shared -L../nvram -L../libutils 
    2222endif 
    23  
    24  
     23ifeq ($(CONFIG_MADWIFI),y) 
     24CCOPTS+=-DHAVE_MADWIFI -DNEED_PRINTF -I../shared  -include $(TOP)/madwifi.dev/madwifi.dev/include/compat.h -DHEADERS_KERNEL 
     25endif 
    2526 
    2627wiviz: ${OBJS} 
  • src/router/wiviz2/channelhopper.c

    r10676 r10677  
    33#include <signal.h> 
    44#include <sys/time.h> 
     5#ifdef HAVE_MADWIFI 
     6#include <sys/mman.h> 
     7#include <stdio.h> 
     8#include <unistd.h> 
     9#include <signal.h> 
     10#include <fcntl.h> 
     11 
     12#include <sys/types.h> 
     13#include <sys/file.h> 
     14#include <sys/ioctl.h> 
     15#include <sys/socket.h> 
     16 
     17#include <stdio.h> 
     18#include <stdlib.h> 
     19#include <string.h> 
     20#include <stdint.h> 
     21#include <ctype.h> 
     22#include <getopt.h> 
     23#include <err.h> 
     24 
     25#include <ctype.h> 
     26#include <string.h> 
     27#include <stdlib.h> 
     28#include <stdio.h> 
     29#include <bcmnvram.h> 
     30#include <bcmutils.h> 
     31#include <shutils.h> 
     32#include <utils.h> 
     33#include <unistd.h> 
     34#include "wireless.h" 
     35#endif 
    536#include "wl_access.h" 
    637#include "channelhopper.h" 
    738#include "structs.h" 
     39 
    840 
    941void ch_sig_handler(int i) { 
     
    1143  } 
    1244 
     45#define IEEE80211_CHAN_2GHZ 1 
     46#define IEEE80211_CHAN_5GHZ 2 
     47u_int ieee80211_ieee2mhz(u_int chan, u_int flags) 
     48{ 
     49        if (flags & IEEE80211_CHAN_2GHZ) {      /* 2GHz band */ 
     50                if (chan == 14) 
     51                        return 2484; 
     52                if (chan < 14) 
     53                        return ((2407) + chan * 5); 
     54                else { 
     55                        if (chan > 236 && chan < 256) { 
     56                                //recalculate offset 
     57                                int newchan = chan - 256; 
     58                                int newfreq = (2407) + (newchan * 5); 
     59                                return newfreq; 
     60                        } else 
     61                                return ((2512) + ((chan - 15) * 20)); 
     62                } 
     63        } else if (flags & IEEE80211_CHAN_5GHZ) /* 5Ghz band */ 
     64                return ((5000) + (chan * 5)); 
     65        else {                  /* either, guess */ 
     66                if (chan == 14) 
     67                        return 2484; 
     68                if (chan < 14)  /* 0-13 */ 
     69                        return ((2407) + chan * 5); 
     70                if (chan < 27)  /* 15-26 */ 
     71                        return ((2512) + ((chan - 15) * 20)); 
     72                if (chan > 236 && chan < 256) { 
     73                        //recalculate offset 
     74                        int newchan = chan - 256; 
     75                        int newfreq = (2407) + (newchan * 5); 
     76                        return newfreq; 
     77                } else 
     78                        return ((5000) + (chan * 5)); 
     79        } 
     80} 
     81 
     82 
     83void set_channel(char *dev,int channel) 
     84{ 
     85    struct iwreq wrq; 
     86    memset( &wrq, 0, sizeof( struct iwreq ) ); 
     87    strncpy( wrq.ifr_name, get_monitor(), IFNAMSIZ ); 
     88    wrq.u.freq.m = (double) ieee80211_ieee2mhz(channel,1) * 100000; 
     89    wrq.u.freq.e = (double) 1; 
     90     
     91    if( ioctl( getsocket(), SIOCSIWFREQ, &wrq ) < 0 ) 
     92    { 
     93        usleep( 10000 ); /* madwifi needs a second chance */ 
     94 
     95        if( ioctl( getsocket(), SIOCSIWFREQ, &wrq ) < 0 ) 
     96        { 
     97            return; 
     98        } 
     99    } 
     100 
     101} 
    13102void channelHopper(wiviz_cfg * cfg) { 
    14103  int hopPos; 
     
    25114    hopPos = (hopPos + 1) % cfg->channelHopSeqLen; 
    26115    //Set the channel 
    27     fprintf(stderr, "It sets the channel to %i\n", nc); 
    28116#ifdef HAVE_MADWIFI 
    29             sysprintf("iwconfig %s channel %d\n",wl_dev,nc); 
     117    set_channel(get_wdev(),nc); 
    30118#else         
    31119    wl_ioctl(get_wdev(), WLC_SET_CHANNEL, &nc, 4); 
  • src/router/wiviz2/wiviz.c

    r10676 r10677  
    1414#include <linux/if_packet.h> 
    1515#include <linux/if_ether.h> 
     16#include <sys/mman.h> 
     17#include <stdio.h> 
     18#include <unistd.h> 
     19#include <signal.h> 
     20#include <fcntl.h> 
     21 
     22#include <sys/types.h> 
     23#include <sys/file.h> 
     24#include <sys/ioctl.h> 
     25#include <sys/socket.h> 
     26 
     27#include <stdio.h> 
     28#include <stdlib.h> 
     29#include <string.h> 
     30#include <stdint.h> 
     31#include <ctype.h> 
     32#include <getopt.h> 
     33#include <err.h> 
     34 
     35#include <ctype.h> 
     36#include <string.h> 
     37#include <stdlib.h> 
     38#include <stdio.h> 
     39#include <bcmnvram.h> 
     40#include <bcmutils.h> 
     41#include <shutils.h> 
     42#include <utils.h> 
     43#include <unistd.h> 
    1644 
    1745#define HOST_TIMEOUT 300 
     
    81109        } 
    82110 
     111#else 
     112          sysprintf("wlanconfig %s create wlandev %s wlanmode monitor",get_monitor(),getWifi(get_wdev())); 
     113          sysprintf("ifconfig %s up",get_monitor()); 
     114          cfg.readFromWl = 1; 
    83115#endif 
    84116  reloadConfig(); 
    85117 
    86118#ifdef HAVE_MADWIFI 
    87   s = openMonitorSocket("mon0"); // for testing we use ath0 
     119  s = openMonitorSocket(get_monitor()); // for testing we use ath0 
    88120#else 
    89121  s = openMonitorSocket("prism0"); 
     
    126158#ifndef HAVE_MADWIFI 
    127159  wl_ioctl(wl_dev, WLC_SET_MONITOR, &oldMonitor, 4); 
    128 #endif 
    129  
     160#else 
     161  sysprintf("ifconfig %s down",get_monitor()); 
     162  sysprintf("wlanconfig %s destroy",get_monitor()); 
     163#endif 
    130164  close(s); 
    131165  return 0; 
     
    265299          if (cfg->readFromWl) { 
    266300#ifdef HAVE_MADWIFI 
    267             sysprintf("iwconfig %s channel %d\n",wl_dev,cfg->curChannel); 
     301            set_channel(wl_dev,cfg->curChannel); 
     302//          sysprintf("iwconfig %s channel %d\n",wl_dev,cfg->curChannel); 
    268303#else         
    269304            if (wl_ioctl(wl_dev, WLC_SET_CHANNEL, &cfg->curChannel, 4) < 0) { 
     
    325360void dealWithPacket(wiviz_cfg * cfg, int pktlen, const u_char * packet) { 
    326361  ieee802_11_hdr * hWifi; 
    327   prism_hdr * hPrism; 
    328362  wiviz_host * host; 
    329363  wiviz_host * emergebss; 
     
    332366  int rssi = 0; 
    333367  int to_ds, from_ds; 
    334   prism_did * i; 
    335368  ieee_802_11_tag * e; 
    336369  ieee_802_11_mgt_frame * m; 
     
    343376  u_char ssidlen = 0; 
    344377  ap_enc_type encType = aetUnknown; 
    345  
    346378  if (!packet) return; 
     379 
     380#ifdef HAVE_MADWIFI 
     381int noise; 
     382  if (packet[0]>0) 
     383    { 
     384    printf( "Wrong radiotap header version.\n" ); 
     385    return; 
     386    } 
     387  int number = packet[2] | (unsigned int)((unsigned int)packet[3]<<8); 
     388    if (number<=0 || number>=pktlen) 
     389        { 
     390        printf("something wrong %d\n",number); 
     391        return; 
     392        } 
     393    noise = packet[number-3]; 
     394    rssi = -(100-(packet[number-4]-noise)); 
     395    hWifi = (ieee802_11_hdr *) (packet + (number)); 
     396#else 
     397  prism_hdr * hPrism; 
     398  prism_did * i; 
    347399  if (pktlen < sizeof(prism_hdr) + sizeof(ieee802_11_hdr)) return; 
     400 
    348401  hPrism = (prism_hdr *) packet; 
    349402  hWifi = (ieee802_11_hdr *) (packet + (hPrism->msg_length)); 
     
    355408    i = (prism_did *) ((int)(i+1) + i->length); 
    356409    } 
     410#endif 
    357411 
    358412  //Establish the frame type 
    359413  wfType = ((hWifi->frame_control & 0xF0) >> 4) + ((hWifi->frame_control & 0xC) << 2); 
     414 
    360415  switch (wfType) { 
    361416    case mgt_assocRequest: 
     
    519574  if (!h->occupied) { 
    520575    printf( "New host, "); 
    521     //fprint_mac(stderr, mac, ", type="); 
     576    fprint_mac(stdout, mac, ", type="); 
    522577    printf( "%s\n", (type==typeAP) ? "AP" : ((type==typeSta) ? "Sta" : "Unk")); 
    523578    } 
     
    600655        get_mac(wl_dev, mac); 
    601656        printf( "AP mac: "); 
    602         //print_mac(mac, "\n"); 
     657        print_mac(mac, "\n"); 
    603658        if (!nonzeromac(mac)) return; 
    604659        if (nvram_nmatch("ap","%s_mode",wl_dev)) 
     
    631686                macs = (maclist_t *) malloc(4 + MAX_STA_COUNT * sizeof(ether_addr_t)); 
    632687                macs->count = MAX_STA_COUNT; 
    633                 if (getassoclist(wl_dev,macs)>-1) 
     688                int code = getassoclist(wl_dev,macs); 
     689                printf("code :%d\n",code); 
     690                if (code>0) 
    634691                { 
    635692                    for (i = 0; i < macs->count; i++) { 
  • src/router/wiviz2/wl_access.c

    r10676 r10677  
    55#include <sys/ioctl.h> 
    66#include <net/if.h> 
     7#include <sys/mman.h> 
     8#include <stdio.h> 
     9#include <unistd.h> 
     10#include <signal.h> 
     11#include <fcntl.h> 
     12 
     13#include <sys/types.h> 
     14#include <sys/file.h> 
     15#include <sys/ioctl.h> 
     16#include <sys/socket.h> 
     17 
     18#include <stdio.h> 
     19#include <stdlib.h> 
     20#include <string.h> 
     21#include <stdint.h> 
     22#include <ctype.h> 
     23#include <getopt.h> 
     24#include <err.h> 
     25 
     26#include <ctype.h> 
     27#include <string.h> 
     28#include <stdlib.h> 
     29#include <stdio.h> 
     30#include <bcmnvram.h> 
     31#include <bcmutils.h> 
     32#include <shutils.h> 
     33#include <utils.h> 
     34#include <unistd.h> 
    735 
    836#include "wl_access.h" 
     
    3361        return ret; 
    3462} 
     63#else 
     64 
     65 
     66char *get_monitor(void) 
     67{ 
     68int devcount; 
     69char *ifname = get_wdev(); 
     70sscanf( ifname, "ath%d", &devcount ); 
     71static char mon[32]; 
     72sprintf(mon,"mon%d",devcount); 
     73return mon; 
     74} 
    3575#endif 
    3676 
  • src/router/wiviz2/wl_access.h

    r5179 r10677  
    22 
    33 
    4 typedef unsigned int uint32; 
    5 typedef unsigned char uchar; 
    6 typedef int bool; 
    74 
    85typedef struct ether_addr { 
Note: See TracChangeset for help on using the changeset viewer.