airo.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:169k
- for(i=0; (int)statsLabels[i]!=-1 &&
- i*4<stats.len; i++){
- if (!statsLabels[i]) continue;
- if (j+strlen(statsLabels[i])+16>4096) {
- printk(KERN_WARNING
- "airo: Potentially disasterous buffer overflow averted!n");
- break;
- }
- j+=sprintf(data->rbuffer+j, "%s: %dn", statsLabels[i], vals[i]);
- }
- if (i*4>=stats.len){
- printk(KERN_WARNING
- "airo: Got a short ridn");
- }
- data->readlen = j;
- return 0;
- }
- static int get_dec_u16( char *buffer, int *start, int limit ) {
- u16 value;
- int valid = 0;
- for( value = 0; buffer[*start] >= '0' &&
- buffer[*start] <= '9' &&
- *start < limit; (*start)++ ) {
- valid = 1;
- value *= 10;
- value += buffer[*start] - '0';
- }
- if ( !valid ) return -1;
- return value;
- }
- static void proc_config_on_close( struct inode *inode, struct file *file ) {
- struct proc_data *data = file->private_data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- Resp rsp;
- char *line;
- int need_reset = 0;
- if ( !data->writelen ) return;
- readConfigRid(ai);
- line = data->wbuffer;
- while( line[0] ) {
- /*** Mode processing */
- if ( !strncmp( line, "Mode: ", 6 ) ) {
- line += 6;
- if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
- need_reset = 1;
- ai->config.rmode &= 0xfe00;
- ai->flags &= ~FLAG_802_11;
- ai->config.opmode &= 0xFF00;
- if ( line[0] == 'a' ) {
- ai->config.opmode |= 0;
- } else {
- ai->config.opmode |= 1;
- if ( line[0] == 'r' ) {
- ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
- ai->flags |= FLAG_802_11;
- } else if ( line[0] == 'y' ) {
- ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
- ai->flags |= FLAG_802_11;
- } else if ( line[0] == 'l' )
- ai->config.rmode |= RXMODE_LANMON;
- }
- ai->need_commit = 1;
- }
- /*** Radio status */
- else if (!strncmp(line,"Radio: ", 7)) {
- line += 7;
- if (!strncmp(line,"off",3)) {
- ai->flags |= FLAG_RADIO_OFF;
- } else {
- ai->flags &= ~FLAG_RADIO_OFF;
- }
- }
- /*** NodeName processing */
- else if ( !strncmp( line, "NodeName: ", 10 ) ) {
- int j;
- line += 10;
- memset( ai->config.nodeName, 0, 16 );
- /* Do the name, assume a space between the mode and node name */
- for( j = 0; j < 16 && line[j] != 'n'; j++ ) {
- ai->config.nodeName[j] = line[j];
- }
- ai->need_commit = 1;
- }
- /*** PowerMode processing */
- else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
- line += 11;
- if ( !strncmp( line, "PSPCAM", 6 ) ) {
- ai->config.powerSaveMode = POWERSAVE_PSPCAM;
- ai->need_commit = 1;
- } else if ( !strncmp( line, "PSP", 3 ) ) {
- ai->config.powerSaveMode = POWERSAVE_PSP;
- ai->need_commit = 1;
- } else {
- ai->config.powerSaveMode = POWERSAVE_CAM;
- ai->need_commit = 1;
- }
- } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
- int v, i = 0, k = 0; /* i is index into line,
- k is index to rates */
- line += 11;
- while((v = get_dec_u16(line, &i, 3))!=-1) {
- ai->config.rates[k++] = (u8)v;
- line += i + 1;
- i = 0;
- }
- ai->need_commit = 1;
- } else if ( !strncmp( line, "Channel: ", 9 ) ) {
- int v, i = 0;
- line += 9;
- v = get_dec_u16(line, &i, i+3);
- if ( v != -1 ) {
- ai->config.channelSet = (u16)v;
- ai->need_commit = 1;
- }
- } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
- int v, i = 0;
- line += 11;
- v = get_dec_u16(line, &i, i+3);
- if ( v != -1 ) {
- ai->config.txPower = (u16)v;
- ai->need_commit = 1;
- }
- } else if ( !strncmp( line, "WEP: ", 5 ) ) {
- line += 5;
- switch( line[0] ) {
- case 's':
- ai->config.authType = (u16)AUTH_SHAREDKEY;
- break;
- case 'e':
- ai->config.authType = (u16)AUTH_ENCRYPT;
- break;
- default:
- ai->config.authType = (u16)AUTH_OPEN;
- break;
- }
- ai->need_commit = 1;
- } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
- int v, i = 0;
- line += 16;
- v = get_dec_u16(line, &i, 3);
- v = (v<0) ? 0 : ((v>255) ? 255 : v);
- ai->config.longRetryLimit = (u16)v;
- ai->need_commit = 1;
- } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
- int v, i = 0;
- line += 17;
- v = get_dec_u16(line, &i, 3);
- v = (v<0) ? 0 : ((v>255) ? 255 : v);
- ai->config.shortRetryLimit = (u16)v;
- ai->need_commit = 1;
- } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
- int v, i = 0;
- line += 14;
- v = get_dec_u16(line, &i, 4);
- v = (v<0) ? 0 : ((v>2312) ? 2312 : v);
- ai->config.rtsThres = (u16)v;
- ai->need_commit = 1;
- } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
- int v, i = 0;
- line += 16;
- v = get_dec_u16(line, &i, 5);
- v = (v<0) ? 0 : v;
- ai->config.txLifetime = (u16)v;
- ai->need_commit = 1;
- } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
- int v, i = 0;
- line += 16;
- v = get_dec_u16(line, &i, 5);
- v = (v<0) ? 0 : v;
- ai->config.rxLifetime = (u16)v;
- ai->need_commit = 1;
- } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
- ai->config.txDiversity =
- (line[13]=='l') ? 1 :
- ((line[13]=='r')? 2: 3);
- ai->need_commit = 1;
- } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
- ai->config.rxDiversity =
- (line[13]=='l') ? 1 :
- ((line[13]=='r')? 2: 3);
- ai->need_commit = 1;
- } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
- int v, i = 0;
- line += 15;
- v = get_dec_u16(line, &i, 4);
- v = (v<256) ? 256 : ((v>2312) ? 2312 : v);
- v = v & 0xfffe; /* Make sure its even */
- ai->config.fragThresh = (u16)v;
- ai->need_commit = 1;
- } else if (!strncmp(line, "Modulation: ", 12)) {
- line += 12;
- switch(*line) {
- case 'd': ai->config.modulation=MOD_DEFAULT; ai->need_commit=1; break;
- case 'c': ai->config.modulation=MOD_CCK; ai->need_commit=1; break;
- case 'm': ai->config.modulation=MOD_MOK; ai->need_commit=1; break;
- default:
- printk( KERN_WARNING "airo: Unknown modulationn" );
- }
- } else if (!strncmp(line, "Preamble: ", 10)) {
- line += 10;
- switch(*line) {
- case 'a': ai->config.preamble=PREAMBLE_AUTO; ai->need_commit=1; break;
- case 'l': ai->config.preamble=PREAMBLE_LONG; ai->need_commit=1; break;
- case 's': ai->config.preamble=PREAMBLE_SHORT; ai->need_commit=1; break;
- default: printk(KERN_WARNING "airo: Unknown preamblen");
- }
- } else {
- printk( KERN_WARNING "Couldn't figure out %sn", line );
- }
- while( line[0] && line[0] != 'n' ) line++;
- if ( line[0] ) line++;
- }
- disable_MAC(ai);
- if (need_reset) {
- APListRid APList_rid;
- SsidRid SSID_rid;
- readAPListRid(ai, &APList_rid);
- readSsidRid(ai, &SSID_rid);
- reset_airo_card(dev);
- disable_MAC(ai);
- writeSsidRid(ai, &SSID_rid);
- writeAPListRid(ai, &APList_rid);
- }
- writeConfigRid(ai);
- enable_MAC(ai, &rsp);
- if (need_reset)
- airo_set_promisc(ai);
- }
- static char *get_rmode(u16 mode) {
- switch(mode&0xff) {
- case RXMODE_RFMON: return "rfmon";
- case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
- case RXMODE_LANMON: return "lanmon";
- }
- return "ESS";
- }
- static int proc_config_open( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- int i;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- if ((data->wbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
- kfree (data->rbuffer);
- kfree (file->private_data);
- return -ENOMEM;
- }
- memset( data->wbuffer, 0, 2048 );
- data->maxwritelen = 2048;
- data->on_close = proc_config_on_close;
- readConfigRid(ai);
- i = sprintf( data->rbuffer,
- "Mode: %sn"
- "Radio: %sn"
- "NodeName: %-16sn"
- "PowerMode: %sn"
- "DataRates: %d %d %d %d %d %d %d %dn"
- "Channel: %dn"
- "XmitPower: %dn",
- (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
- (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
- (ai->config.opmode & 0xFF) == 2 ? "AP" :
- (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
- ai->flags&FLAG_RADIO_OFF ? "off" : "on",
- ai->config.nodeName,
- ai->config.powerSaveMode == 0 ? "CAM" :
- ai->config.powerSaveMode == 1 ? "PSP" :
- ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
- (int)ai->config.rates[0],
- (int)ai->config.rates[1],
- (int)ai->config.rates[2],
- (int)ai->config.rates[3],
- (int)ai->config.rates[4],
- (int)ai->config.rates[5],
- (int)ai->config.rates[6],
- (int)ai->config.rates[7],
- (int)ai->config.channelSet,
- (int)ai->config.txPower
- );
- sprintf( data->rbuffer + i,
- "LongRetryLimit: %dn"
- "ShortRetryLimit: %dn"
- "RTSThreshold: %dn"
- "TXMSDULifetime: %dn"
- "RXMSDULifetime: %dn"
- "TXDiversity: %sn"
- "RXDiversity: %sn"
- "FragThreshold: %dn"
- "WEP: %sn"
- "Modulation: %sn"
- "Preamble: %sn",
- (int)ai->config.longRetryLimit,
- (int)ai->config.shortRetryLimit,
- (int)ai->config.rtsThres,
- (int)ai->config.txLifetime,
- (int)ai->config.rxLifetime,
- ai->config.txDiversity == 1 ? "left" :
- ai->config.txDiversity == 2 ? "right" : "both",
- ai->config.rxDiversity == 1 ? "left" :
- ai->config.rxDiversity == 2 ? "right" : "both",
- (int)ai->config.fragThresh,
- ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
- ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
- ai->config.modulation == 0 ? "default" :
- ai->config.modulation == MOD_CCK ? "cck" :
- ai->config.modulation == MOD_MOK ? "mok" : "error",
- ai->config.preamble == PREAMBLE_AUTO ? "auto" :
- ai->config.preamble == PREAMBLE_LONG ? "long" :
- ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
- );
- data->readlen = strlen( data->rbuffer );
- return 0;
- }
- static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
- struct proc_data *data = (struct proc_data *)file->private_data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- SsidRid SSID_rid;
- Resp rsp;
- int i;
- int offset = 0;
- if ( !data->writelen ) return;
- memset( &SSID_rid, 0, sizeof( SSID_rid ) );
- for( i = 0; i < 3; i++ ) {
- int j;
- for( j = 0; j+offset < data->writelen && j < 32 &&
- data->wbuffer[offset+j] != 'n'; j++ ) {
- SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
- }
- if ( j == 0 ) break;
- SSID_rid.ssids[i].len = j;
- offset += j;
- while( data->wbuffer[offset] != 'n' &&
- offset < data->writelen ) offset++;
- offset++;
- }
- disable_MAC(ai);
- writeSsidRid(ai, &SSID_rid);
- enable_MAC(ai, &rsp);
- }
- inline static u8 hexVal(char c) {
- if (c>='0' && c<='9') return c -= '0';
- if (c>='a' && c<='f') return c -= 'a'-10;
- if (c>='A' && c<='F') return c -= 'A'-10;
- return 0;
- }
- static void proc_APList_on_close( struct inode *inode, struct file *file ) {
- struct proc_data *data = (struct proc_data *)file->private_data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- APListRid APList_rid;
- Resp rsp;
- int i;
- if ( !data->writelen ) return;
- memset( &APList_rid, 0, sizeof(APList_rid) );
- APList_rid.len = sizeof(APList_rid);
- for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
- int j;
- for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
- switch(j%3) {
- case 0:
- APList_rid.ap[i][j/3]=
- hexVal(data->wbuffer[j+i*6*3])<<4;
- break;
- case 1:
- APList_rid.ap[i][j/3]|=
- hexVal(data->wbuffer[j+i*6*3]);
- break;
- }
- }
- }
- disable_MAC(ai);
- writeAPListRid(ai, &APList_rid);
- enable_MAC(ai, &rsp);
- }
- /* This function wraps PC4500_writerid with a MAC disable */
- static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
- int len ) {
- int rc;
- Resp rsp;
- disable_MAC(ai);
- rc = PC4500_writerid(ai, rid, rid_data, len);
- enable_MAC(ai, &rsp);
- return rc;
- }
- /* Returns the length of the key at the index. If index == 0xffff
- * the index of the transmit key is returned. If the key doesn't exist,
- * -1 will be returned.
- */
- static int get_wep_key(struct airo_info *ai, u16 index) {
- WepKeyRid wkr;
- int rc;
- u16 lastindex;
- rc = readWepKeyRid(ai, &wkr, 1);
- if (rc == SUCCESS) do {
- lastindex = wkr.kindex;
- if (wkr.kindex == index) {
- if (index == 0xffff) {
- return wkr.mac[0];
- }
- return wkr.klen;
- }
- readWepKeyRid(ai, &wkr, 0);
- } while(lastindex != wkr.kindex);
- return -1;
- }
- static int set_wep_key(struct airo_info *ai, u16 index,
- const char *key, u16 keylen, int perm ) {
- static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
- WepKeyRid wkr;
- memset(&wkr, 0, sizeof(wkr));
- if (keylen == 0) {
- // We are selecting which key to use
- wkr.len = sizeof(wkr);
- wkr.kindex = 0xffff;
- wkr.mac[0] = (char)index;
- if (perm) printk(KERN_INFO "Setting transmit key to %dn", index);
- if (perm) ai->defindex = (char)index;
- } else {
- // We are actually setting the key
- wkr.len = sizeof(wkr);
- wkr.kindex = index;
- wkr.klen = keylen;
- memcpy( wkr.key, key, keylen );
- memcpy( wkr.mac, macaddr, ETH_ALEN );
- printk(KERN_INFO "Setting key %dn", index);
- }
- writeWepKeyRid(ai, &wkr, perm);
- return 0;
- }
- static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- int i;
- char key[16];
- u16 index = 0;
- int j = 0;
- memset(key, 0, sizeof(key));
- data = (struct proc_data *)file->private_data;
- if ( !data->writelen ) return;
- if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
- (data->wbuffer[1] == ' ' || data->wbuffer[1] == 'n')) {
- index = data->wbuffer[0] - '0';
- if (data->wbuffer[1] == 'n') {
- set_wep_key(ai, index, 0, 0, 1);
- return;
- }
- j = 2;
- } else {
- printk(KERN_ERR "airo: WepKey passed invalid key indexn");
- return;
- }
- for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
- switch(i%3) {
- case 0:
- key[i/3] = hexVal(data->wbuffer[i+j])<<4;
- break;
- case 1:
- key[i/3] |= hexVal(data->wbuffer[i+j]);
- break;
- }
- }
- set_wep_key(ai, index, key, i/3, 1);
- }
- static int proc_wepkey_open( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- char *ptr;
- WepKeyRid wkr;
- u16 lastindex;
- int j=0;
- int rc;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- memset(&wkr, 0, sizeof(wkr));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 180, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- memset(data->rbuffer, 0, 180);
- data->writelen = 0;
- data->maxwritelen = 80;
- if ((data->wbuffer = kmalloc( 80, GFP_KERNEL )) == NULL) {
- kfree (data->rbuffer);
- kfree (file->private_data);
- return -ENOMEM;
- }
- memset( data->wbuffer, 0, 80 );
- data->on_close = proc_wepkey_on_close;
- ptr = data->rbuffer;
- strcpy(ptr, "No wep keysn");
- rc = readWepKeyRid(ai, &wkr, 1);
- if (rc == SUCCESS) do {
- lastindex = wkr.kindex;
- if (wkr.kindex == 0xffff) {
- j += sprintf(ptr+j, "Tx key = %dn",
- (int)wkr.mac[0]);
- } else {
- j += sprintf(ptr+j, "Key %d set with length = %dn",
- (int)wkr.kindex, (int)wkr.klen);
- }
- readWepKeyRid(ai, &wkr, 0);
- } while((lastindex != wkr.kindex) && (j < 180-30));
- data->readlen = strlen( data->rbuffer );
- return 0;
- }
- static int proc_SSID_open( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- int i;
- char *ptr;
- SsidRid SSID_rid;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- data->writelen = 0;
- data->maxwritelen = 33*3;
- if ((data->wbuffer = kmalloc( 33*3, GFP_KERNEL )) == NULL) {
- kfree (data->rbuffer);
- kfree (file->private_data);
- return -ENOMEM;
- }
- memset( data->wbuffer, 0, 33*3 );
- data->on_close = proc_SSID_on_close;
- readSsidRid(ai, &SSID_rid);
- ptr = data->rbuffer;
- for( i = 0; i < 3; i++ ) {
- int j;
- if ( !SSID_rid.ssids[i].len ) break;
- for( j = 0; j < 32 &&
- j < SSID_rid.ssids[i].len &&
- SSID_rid.ssids[i].ssid[j]; j++ ) {
- *ptr++ = SSID_rid.ssids[i].ssid[j];
- }
- *ptr++ = 'n';
- }
- *ptr = ' ';
- data->readlen = strlen( data->rbuffer );
- return 0;
- }
- static int proc_APList_open( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- int i;
- char *ptr;
- APListRid APList_rid;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- data->writelen = 0;
- data->maxwritelen = 4*6*3;
- if ((data->wbuffer = kmalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
- kfree (data->rbuffer);
- kfree (file->private_data);
- return -ENOMEM;
- }
- memset( data->wbuffer, 0, data->maxwritelen );
- data->on_close = proc_APList_on_close;
- readAPListRid(ai, &APList_rid);
- ptr = data->rbuffer;
- for( i = 0; i < 4; i++ ) {
- // We end when we find a zero MAC
- if ( !*(int*)APList_rid.ap[i] &&
- !*(int*)&APList_rid.ap[i][2]) break;
- ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02xn",
- (int)APList_rid.ap[i][0],
- (int)APList_rid.ap[i][1],
- (int)APList_rid.ap[i][2],
- (int)APList_rid.ap[i][3],
- (int)APList_rid.ap[i][4],
- (int)APList_rid.ap[i][5]);
- }
- if (i==0) ptr += sprintf(ptr, "Not using specific APsn");
- *ptr = ' ';
- data->readlen = strlen( data->rbuffer );
- return 0;
- }
- static int proc_BSSList_open( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *ai = dev->priv;
- char *ptr;
- BSSListRid BSSList_rid;
- int rc;
- /* If doLoseSync is not 1, we won't do a Lose Sync */
- int doLoseSync = -1;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- data->writelen = 0;
- data->maxwritelen = 0;
- data->wbuffer = 0;
- data->on_close = 0;
- if (file->f_mode & FMODE_WRITE) {
- if (!(file->f_mode & FMODE_READ)) {
- Cmd cmd;
- Resp rsp;
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd=CMD_LISTBSS;
- if (down_interruptible(&ai->sem))
- return -ERESTARTSYS;
- issuecommand(ai, &cmd, &rsp);
- up(&ai->sem);
- data->readlen = 0;
- return 0;
- }
- doLoseSync = 1;
- }
- ptr = data->rbuffer;
- /* There is a race condition here if there are concurrent opens.
- Since it is a rare condition, we'll just live with it, otherwise
- we have to add a spin lock... */
- rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
- while(rc == 0 && BSSList_rid.index != 0xffff) {
- ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
- (int)BSSList_rid.bssid[0],
- (int)BSSList_rid.bssid[1],
- (int)BSSList_rid.bssid[2],
- (int)BSSList_rid.bssid[3],
- (int)BSSList_rid.bssid[4],
- (int)BSSList_rid.bssid[5],
- (int)BSSList_rid.ssidLen,
- BSSList_rid.ssid,
- (int)BSSList_rid.rssi);
- ptr += sprintf(ptr, " channel = %d %s %s %s %sn",
- (int)BSSList_rid.dsChannel,
- BSSList_rid.cap & CAP_ESS ? "ESS" : "",
- BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
- BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
- BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
- rc = readBSSListRid(ai, 0, &BSSList_rid);
- }
- *ptr = ' ';
- data->readlen = strlen( data->rbuffer );
- return 0;
- }
- static int proc_close( struct inode *inode, struct file *file )
- {
- struct proc_data *data = (struct proc_data *)file->private_data;
- if ( data->on_close != NULL ) data->on_close( inode, file );
- MOD_DEC_USE_COUNT;
- if ( data->rbuffer ) kfree( data->rbuffer );
- if ( data->wbuffer ) kfree( data->wbuffer );
- kfree( data );
- return 0;
- }
- static struct net_device_list {
- struct net_device *dev;
- struct net_device_list *next;
- } *airo_devices = 0;
- /* Since the card doesn't automatically switch to the right WEP mode,
- we will make it do it. If the card isn't associated, every secs we
- will switch WEP modes to see if that will help. If the card is
- associated we will check every minute to see if anything has
- changed. */
- static void timer_func( u_long data ) {
- struct net_device *dev = (struct net_device*)data;
- struct airo_info *apriv = dev->priv;
- u16 linkstat = IN4500(apriv, LINKSTAT);
- Resp rsp;
- if (!(apriv->flags & FLAG_FLASHING) && (linkstat != 0x400)) {
- /* We don't have a link so try changing the authtype */
- if (down_trylock(&apriv->sem) != 0) {
- apriv->timer.expires = RUN_AT(1);
- add_timer(&apriv->timer);
- return;
- }
- __set_bit(FLAG_LOCKED, &apriv->flags);
- readConfigRid(apriv);
- disable_MAC(apriv);
- switch(apriv->config.authType) {
- case AUTH_ENCRYPT:
- /* So drop to OPEN */
- apriv->config.authType = AUTH_OPEN;
- break;
- case AUTH_SHAREDKEY:
- if (apriv->keyindex < auto_wep) {
- set_wep_key(apriv, apriv->keyindex, 0, 0, 0);
- apriv->config.authType = AUTH_SHAREDKEY;
- apriv->keyindex++;
- } else {
- /* Drop to ENCRYPT */
- apriv->keyindex = 0;
- set_wep_key(apriv, apriv->defindex, 0, 0, 0);
- apriv->config.authType = AUTH_ENCRYPT;
- }
- break;
- default: /* We'll escalate to SHAREDKEY */
- apriv->config.authType = AUTH_SHAREDKEY;
- }
- apriv->need_commit = 1;
- writeConfigRid(apriv);
- enable_MAC(apriv, &rsp);
- clear_bit(FLAG_LOCKED, &apriv->flags);
- up(&apriv->sem);
- /* Schedule check to see if the change worked */
- apriv->timer.expires = RUN_AT(HZ*3);
- add_timer(&apriv->timer);
- }
- }
- static int add_airo_dev( struct net_device *dev ) {
- struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL );
- if ( !node )
- return -ENOMEM;
- if ( auto_wep ) {
- struct airo_info *apriv=dev->priv;
- struct timer_list *timer = &apriv->timer;
- timer->function = timer_func;
- timer->data = (u_long)dev;
- init_timer(timer);
- }
- node->dev = dev;
- node->next = airo_devices;
- airo_devices = node;
- return 0;
- }
- static void del_airo_dev( struct net_device *dev ) {
- struct net_device_list **p = &airo_devices;
- while( *p && ( (*p)->dev != dev ) )
- p = &(*p)->next;
- if ( *p && (*p)->dev == dev )
- *p = (*p)->next;
- }
- #ifdef CONFIG_PCI
- static int __devinit airo_pci_probe(struct pci_dev *pdev,
- const struct pci_device_id *pent)
- {
- struct net_device *dev;
- dev = init_airo_card(pdev->irq, pdev->resource[2].start, 0);
- if (!dev)
- return -ENODEV;
- pci_set_drvdata(pdev, dev);
- return 0;
- }
- static void __devexit airo_pci_remove(struct pci_dev *pdev)
- {
- stop_airo_card(pci_get_drvdata(pdev), 1);
- }
- #endif
- static int __init airo_init_module( void )
- {
- int i, rc = 0, have_isa_dev = 0;
- airo_entry = create_proc_entry("aironet",
- S_IFDIR | airo_perm,
- proc_root_driver);
- airo_entry->uid = proc_uid;
- airo_entry->gid = proc_gid;
- for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
- printk( KERN_INFO
- "airo: Trying to configure ISA adapter at irq=%d io=0x%xn",
- irq[i], io[i] );
- if (init_airo_card( irq[i], io[i], 0 ))
- have_isa_dev = 1;
- }
- #ifdef CONFIG_PCI
- printk( KERN_INFO "airo: Probing for PCI adaptersn" );
- rc = pci_module_init(&airo_driver);
- printk( KERN_INFO "airo: Finished probing for PCI adaptersn" );
- #endif
- /* Always exit with success, as we are a library module
- * as well as a driver module
- */
- return 0;
- }
- static void __exit airo_cleanup_module( void )
- {
- while( airo_devices ) {
- printk( KERN_INFO "airo: Unregistering %sn", airo_devices->dev->name );
- stop_airo_card( airo_devices->dev, 1 );
- }
- remove_proc_entry("aironet", proc_root_driver);
- }
- #ifdef WIRELESS_EXT
- /*
- * Initial Wireless Extension code for Aironet driver by :
- * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
- * Conversion to new driver API by :
- * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
- * Javier also did a good amount of work here, adding some new extensions
- * and fixing my code. Let's just say that without him this code just
- * would not work at all... - Jean II
- */
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get protocol name
- */
- static int airo_get_name(struct net_device *dev,
- struct iw_request_info *info,
- char *cwrq,
- char *extra)
- {
- strcpy(cwrq, "IEEE 802.11-DS");
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set frequency
- */
- static int airo_set_freq(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_freq *fwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- int rc = -EINPROGRESS; /* Call commit handler */
- /* If setting by frequency, convert to a channel */
- if((fwrq->e == 1) &&
- (fwrq->m >= (int) 2.412e8) &&
- (fwrq->m <= (int) 2.487e8)) {
- int f = fwrq->m / 100000;
- int c = 0;
- while((c < 14) && (f != frequency_list[c]))
- c++;
- /* Hack to fall through... */
- fwrq->e = 0;
- fwrq->m = c + 1;
- }
- /* Setting by channel number */
- if((fwrq->m > 1000) || (fwrq->e > 0))
- rc = -EOPNOTSUPP;
- else {
- int channel = fwrq->m;
- /* We should do a better check than that,
- * based on the card capability !!! */
- if((channel < 1) || (channel > 16)) {
- printk(KERN_DEBUG "%s: New channel value of %d is invalid!n", dev->name, fwrq->m);
- rc = -EINVAL;
- } else {
- /* Yes ! We can set it !!! */
- local->config.channelSet = (u16)(channel - 1);
- local->need_commit = 1;
- }
- }
- return rc;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get frequency
- */
- static int airo_get_freq(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_freq *fwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- StatusRid status_rid; /* Card status info */
- readStatusRid(local, &status_rid);
- /* Will return zero in infrastructure mode */
- #ifdef WEXT_USECHANNELS
- fwrq->m = ((int)status_rid.channel) + 1;
- fwrq->e = 0;
- #else
- {
- int f = (int)status_rid.channel;
- fwrq->m = frequency_list[f] * 100000;
- fwrq->e = 1;
- }
- #endif
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set ESSID
- */
- static int airo_set_essid(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- Resp rsp;
- SsidRid SSID_rid; /* SSIDs */
- /* Reload the list of current SSID */
- readSsidRid(local, &SSID_rid);
- /* Check if we asked for `any' */
- if(dwrq->flags == 0) {
- /* Just send an empty SSID list */
- memset(&SSID_rid, 0, sizeof(SSID_rid));
- } else {
- int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
- /* Check the size of the string */
- if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
- return -E2BIG ;
- }
- /* Check if index is valid */
- if((index < 0) || (index >= 4)) {
- return -EINVAL;
- }
- /* Set the SSID */
- memset(SSID_rid.ssids[index].ssid, 0,
- sizeof(SSID_rid.ssids[index].ssid));
- memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
- SSID_rid.ssids[index].len = dwrq->length - 1;
- }
- /* Write it to the card */
- disable_MAC(local);
- writeSsidRid(local, &SSID_rid);
- enable_MAC(local, &rsp);
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get ESSID
- */
- static int airo_get_essid(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- StatusRid status_rid; /* Card status info */
- readStatusRid(local, &status_rid);
- /* Note : if dwrq->flags != 0, we should
- * get the relevant SSID from the SSID list... */
- /* Get the current SSID */
- memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
- extra[status_rid.SSIDlen] = ' ';
- /* If none, we may want to get the one that was set */
- /* Push it out ! */
- dwrq->length = status_rid.SSIDlen + 1;
- dwrq->flags = 1; /* active */
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set AP address
- */
- static int airo_set_wap(struct net_device *dev,
- struct iw_request_info *info,
- struct sockaddr *awrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- Cmd cmd;
- Resp rsp;
- APListRid APList_rid;
- static const unsigned char bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
- if (awrq->sa_family != ARPHRD_ETHER)
- return -EINVAL;
- else if (!memcmp(bcast, awrq->sa_data, ETH_ALEN)) {
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd=CMD_LOSE_SYNC;
- if (down_interruptible(&local->sem))
- return -ERESTARTSYS;
- issuecommand(local, &cmd, &rsp);
- up(&local->sem);
- } else {
- memset(&APList_rid, 0, sizeof(APList_rid));
- APList_rid.len = sizeof(APList_rid);
- memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
- disable_MAC(local);
- writeAPListRid(local, &APList_rid);
- enable_MAC(local, &rsp);
- }
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get AP address
- */
- static int airo_get_wap(struct net_device *dev,
- struct iw_request_info *info,
- struct sockaddr *awrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- StatusRid status_rid; /* Card status info */
- readStatusRid(local, &status_rid);
- /* Tentative. This seems to work, wow, I'm lucky !!! */
- memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
- awrq->sa_family = ARPHRD_ETHER;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Nickname
- */
- static int airo_set_nick(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- /* Check the size of the string */
- if(dwrq->length > 16 + 1) {
- return -E2BIG;
- }
- memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
- memcpy(local->config.nodeName, extra, dwrq->length);
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Nickname
- */
- static int airo_get_nick(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- strncpy(extra, local->config.nodeName, 16);
- extra[16] = ' ';
- dwrq->length = strlen(extra) + 1;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Bit-Rate
- */
- static int airo_set_rate(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- CapabilityRid cap_rid; /* Card capability info */
- u8 brate = 0;
- int i;
- /* First : get a valid bit rate value */
- readCapabilityRid(local, &cap_rid);
- /* Which type of value ? */
- if((vwrq->value < 8) && (vwrq->value >= 0)) {
- /* Setting by rate index */
- /* Find value in the magic rate table */
- brate = cap_rid.supportedRates[vwrq->value];
- } else {
- /* Setting by frequency value */
- u8 normvalue = (u8) (vwrq->value/500000);
- /* Check if rate is valid */
- for(i = 0 ; i < 8 ; i++) {
- if(normvalue == cap_rid.supportedRates[i]) {
- brate = normvalue;
- break;
- }
- }
- }
- /* -1 designed the max rate (mostly auto mode) */
- if(vwrq->value == -1) {
- /* Get the highest available rate */
- for(i = 0 ; i < 8 ; i++) {
- if(cap_rid.supportedRates[i] == 0)
- break;
- }
- if(i != 0)
- brate = cap_rid.supportedRates[i - 1];
- }
- /* Check that it is valid */
- if(brate == 0) {
- return -EINVAL;
- }
- /* Now, check if we want a fixed or auto value */
- if(vwrq->fixed == 0) {
- /* Fill all the rates up to this max rate */
- memset(local->config.rates, 0, 8);
- for(i = 0 ; i < 8 ; i++) {
- local->config.rates[i] = cap_rid.supportedRates[i];
- if(local->config.rates[i] == brate)
- break;
- }
- } else {
- /* Fixed mode */
- /* One rate, fixed */
- memset(local->config.rates, 0, 8);
- local->config.rates[0] = brate;
- }
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Bit-Rate
- */
- static int airo_get_rate(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- StatusRid status_rid; /* Card status info */
- readStatusRid(local, &status_rid);
- vwrq->value = status_rid.currentXmitRate * 500000;
- /* If more than one rate, set auto */
- vwrq->fixed = (local->config.rates[1] == 0);
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set RTS threshold
- */
- static int airo_set_rts(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- int rthr = vwrq->value;
- if(vwrq->disabled)
- rthr = 2312;
- if((rthr < 0) || (rthr > 2312)) {
- return -EINVAL;
- }
- local->config.rtsThres = rthr;
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get RTS threshold
- */
- static int airo_get_rts(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- vwrq->value = local->config.rtsThres;
- vwrq->disabled = (vwrq->value >= 2312);
- vwrq->fixed = 1;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Fragmentation threshold
- */
- static int airo_set_frag(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- int fthr = vwrq->value;
- if(vwrq->disabled)
- fthr = 2312;
- if((fthr < 256) || (fthr > 2312)) {
- return -EINVAL;
- }
- fthr &= ~0x1; /* Get an even value - is it really needed ??? */
- local->config.fragThresh = (u16)fthr;
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Fragmentation threshold
- */
- static int airo_get_frag(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- vwrq->value = local->config.fragThresh;
- vwrq->disabled = (vwrq->value >= 2312);
- vwrq->fixed = 1;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Mode of Operation
- */
- static int airo_set_mode(struct net_device *dev,
- struct iw_request_info *info,
- __u32 *uwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- switch(*uwrq) {
- case IW_MODE_ADHOC:
- local->config.opmode &= 0xFF00;
- local->config.opmode |= MODE_STA_IBSS;
- break;
- case IW_MODE_INFRA:
- local->config.opmode &= 0xFF00;
- local->config.opmode |= MODE_STA_ESS;
- break;
- case IW_MODE_MASTER:
- local->config.opmode &= 0xFF00;
- local->config.opmode |= MODE_AP;
- break;
- case IW_MODE_REPEAT:
- local->config.opmode &= 0xFF00;
- local->config.opmode |= MODE_AP_RPTR;
- break;
- default:
- return -EINVAL;
- }
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Mode of Operation
- */
- static int airo_get_mode(struct net_device *dev,
- struct iw_request_info *info,
- __u32 *uwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- /* If not managed, assume it's ad-hoc */
- switch (local->config.opmode & 0xFF) {
- case MODE_STA_ESS:
- *uwrq = IW_MODE_INFRA;
- break;
- case MODE_AP:
- *uwrq = IW_MODE_MASTER;
- break;
- case MODE_AP_RPTR:
- *uwrq = IW_MODE_REPEAT;
- break;
- default:
- *uwrq = IW_MODE_ADHOC;
- }
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Encryption Key
- */
- static int airo_set_encode(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- CapabilityRid cap_rid; /* Card capability info */
- /* Is WEP supported ? */
- readCapabilityRid(local, &cap_rid);
- /* Older firmware doesn't support this...
- if(!(cap_rid.softCap & 2)) {
- return -EOPNOTSUPP;
- } */
- /* Basic checking: do we have a key to set ?
- * Note : with the new API, it's impossible to get a NULL pointer.
- * Therefore, we need to check a key size == 0 instead.
- * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
- * when no key is present (only change flags), but older versions
- * don't do it. - Jean II */
- if (dwrq->length > 0) {
- wep_key_t key;
- int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
- int current_index = get_wep_key(local, 0xffff);
- /* Check the size of the key */
- if (dwrq->length > MAX_KEY_SIZE) {
- return -EINVAL;
- }
- /* Check the index (none -> use current) */
- if ((index < 0) || (index>=(cap_rid.softCap&0x80)?4:1))
- index = current_index;
- /* Set the length */
- if (dwrq->length > MIN_KEY_SIZE)
- key.len = MAX_KEY_SIZE;
- else
- if (dwrq->length > 0)
- key.len = MIN_KEY_SIZE;
- else
- /* Disable the key */
- key.len = 0;
- /* Check if the key is not marked as invalid */
- if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
- /* Cleanup */
- memset(key.key, 0, MAX_KEY_SIZE);
- /* Copy the key in the driver */
- memcpy(key.key, extra, dwrq->length);
- /* Send the key to the card */
- set_wep_key(local, index, key.key, key.len, 1);
- }
- /* WE specify that if a valid key is set, encryption
- * should be enabled (user may turn it off later)
- * This is also how "iwconfig ethX key on" works */
- if((index == current_index) && (key.len > 0) &&
- (local->config.authType == AUTH_OPEN)) {
- local->config.authType = AUTH_ENCRYPT;
- local->need_commit = 1;
- }
- } else {
- /* Do we want to just set the transmit key index ? */
- int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
- if ((index>=0) && (index<(cap_rid.softCap&0x80)?4:1)) {
- set_wep_key(local, index, 0, 0, 1);
- } else
- /* Don't complain if only change the mode */
- if(!dwrq->flags & IW_ENCODE_MODE) {
- return -EINVAL;
- }
- }
- /* Read the flags */
- if(dwrq->flags & IW_ENCODE_DISABLED)
- local->config.authType = AUTH_OPEN; // disable encryption
- if(dwrq->flags & IW_ENCODE_RESTRICTED)
- local->config.authType = AUTH_SHAREDKEY; // Only Both
- if(dwrq->flags & IW_ENCODE_OPEN)
- local->config.authType = AUTH_ENCRYPT; // Only Wep
- /* Commit the changes to flags if needed */
- if(dwrq->flags & IW_ENCODE_MODE)
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Encryption Key
- */
- static int airo_get_encode(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
- CapabilityRid cap_rid; /* Card capability info */
- /* Is it supported ? */
- readCapabilityRid(local, &cap_rid);
- if(!(cap_rid.softCap & 2)) {
- return -EOPNOTSUPP;
- }
- /* Check encryption mode */
- switch(local->config.authType) {
- case AUTH_ENCRYPT:
- dwrq->flags = IW_ENCODE_OPEN;
- break;
- case AUTH_SHAREDKEY:
- dwrq->flags = IW_ENCODE_RESTRICTED;
- break;
- default:
- case AUTH_OPEN:
- dwrq->flags = IW_ENCODE_DISABLED;
- break;
- }
- /* We can't return the key, so set the proper flag and return zero */
- dwrq->flags |= IW_ENCODE_NOKEY;
- memset(extra, 0, 16);
- /* Which key do we want ? -1 -> tx index */
- if((index < 0) || (index >= (cap_rid.softCap & 0x80) ? 4 : 1))
- index = get_wep_key(local, 0xffff);
- dwrq->flags |= index + 1;
- /* Copy the key to the user buffer */
- dwrq->length = get_wep_key(local, index);
- if (dwrq->length > 16) {
- dwrq->length=0;
- }
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Tx-Power
- */
- static int airo_set_txpow(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- CapabilityRid cap_rid; /* Card capability info */
- int i;
- int rc = -EINVAL;
- readCapabilityRid(local, &cap_rid);
- if (vwrq->disabled) {
- local->flags |= FLAG_RADIO_OFF;
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- if (vwrq->flags != IW_TXPOW_MWATT) {
- return -EINVAL;
- }
- local->flags &= ~FLAG_RADIO_OFF;
- for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
- if ((vwrq->value==cap_rid.txPowerLevels[i])) {
- local->config.txPower = vwrq->value;
- local->need_commit = 1;
- rc = -EINPROGRESS; /* Call commit handler */
- break;
- }
- return rc;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Tx-Power
- */
- static int airo_get_txpow(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- vwrq->value = local->config.txPower;
- vwrq->fixed = 1; /* No power control */
- vwrq->disabled = (local->flags & FLAG_RADIO_OFF);
- vwrq->flags = IW_TXPOW_MWATT;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Retry limits
- */
- static int airo_set_retry(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- int rc = -EINVAL;
- if(vwrq->disabled) {
- return -EINVAL;
- }
- if(vwrq->flags & IW_RETRY_LIMIT) {
- if(vwrq->flags & IW_RETRY_MAX)
- local->config.longRetryLimit = vwrq->value;
- else if (vwrq->flags & IW_RETRY_MIN)
- local->config.shortRetryLimit = vwrq->value;
- else {
- /* No modifier : set both */
- local->config.longRetryLimit = vwrq->value;
- local->config.shortRetryLimit = vwrq->value;
- }
- local->need_commit = 1;
- rc = -EINPROGRESS; /* Call commit handler */
- }
- if(vwrq->flags & IW_RETRY_LIFETIME) {
- local->config.txLifetime = vwrq->value / 1024;
- local->need_commit = 1;
- rc = -EINPROGRESS; /* Call commit handler */
- }
- return rc;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Retry limits
- */
- static int airo_get_retry(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- vwrq->disabled = 0; /* Can't be disabled */
- /* Note : by default, display the min retry number */
- if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
- vwrq->flags = IW_RETRY_LIFETIME;
- vwrq->value = (int)local->config.txLifetime * 1024;
- } else if((vwrq->flags & IW_RETRY_MAX)) {
- vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
- vwrq->value = (int)local->config.longRetryLimit;
- } else {
- vwrq->flags = IW_RETRY_LIMIT;
- vwrq->value = (int)local->config.shortRetryLimit;
- if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
- vwrq->flags |= IW_RETRY_MIN;
- }
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get range info
- */
- static int airo_get_range(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- struct iw_range *range = (struct iw_range *) extra;
- CapabilityRid cap_rid; /* Card capability info */
- int i;
- int k;
- readCapabilityRid(local, &cap_rid);
- dwrq->length = sizeof(struct iw_range);
- memset(range, 0, sizeof(range));
- range->min_nwid = 0x0000;
- range->max_nwid = 0x0000;
- range->num_channels = 14;
- /* Should be based on cap_rid.country to give only
- * what the current card support */
- k = 0;
- for(i = 0; i < 14; i++) {
- range->freq[k].i = i + 1; /* List index */
- range->freq[k].m = frequency_list[i] * 100000;
- range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
- }
- range->num_frequency = k;
- /* Hum... Should put the right values there */
- range->max_qual.qual = 10;
- range->max_qual.level = 0x100 - 120; /* -120 dBm */
- range->max_qual.noise = 0;
- range->sensitivity = 65535;
- for(i = 0 ; i < 8 ; i++) {
- range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
- if(range->bitrate[i] == 0)
- break;
- }
- range->num_bitrates = i;
- /* Set an indication of the max TCP throughput
- * in bit/s that we can expect using this interface.
- * May be use for QoS stuff... Jean II */
- if(i > 2)
- range->throughput = 5000 * 1000;
- else
- range->throughput = 1500 * 1000;
- range->min_rts = 0;
- range->max_rts = 2312;
- range->min_frag = 256;
- range->max_frag = 2312;
- if(cap_rid.softCap & 2) {
- // WEP: RC4 40 bits
- range->encoding_size[0] = 5;
- // RC4 ~128 bits
- if (cap_rid.softCap & 0x100) {
- range->encoding_size[1] = 13;
- range->num_encoding_sizes = 2;
- } else
- range->num_encoding_sizes = 1;
- range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
- } else {
- range->num_encoding_sizes = 0;
- range->max_encoding_tokens = 0;
- }
- range->min_pmp = 0;
- range->max_pmp = 5000000; /* 5 secs */
- range->min_pmt = 0;
- range->max_pmt = 65535 * 1024; /* ??? */
- range->pmp_flags = IW_POWER_PERIOD;
- range->pmt_flags = IW_POWER_TIMEOUT;
- range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
- /* Transmit Power - values are in mW */
- for(i = 0 ; i < 8 ; i++) {
- range->txpower[i] = cap_rid.txPowerLevels[i];
- if(range->txpower[i] == 0)
- break;
- }
- range->num_txpower = i;
- range->txpower_capa = IW_TXPOW_MWATT;
- range->we_version_source = 12;
- range->we_version_compiled = WIRELESS_EXT;
- range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
- range->retry_flags = IW_RETRY_LIMIT;
- range->r_time_flags = IW_RETRY_LIFETIME;
- range->min_retry = 1;
- range->max_retry = 65535;
- range->min_r_time = 1024;
- range->max_r_time = 65535 * 1024;
- /* Experimental measurements - boundary 11/5.5 Mb/s */
- /* Note : with or without the (local->rssi), results
- * are somewhat different. - Jean II */
- range->avg_qual.qual = 6;
- if (local->rssi)
- range->avg_qual.level = 186; /* -70 dBm */
- else
- range->avg_qual.level = 176; /* -80 dBm */
- range->avg_qual.noise = 0;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Power Management
- */
- static int airo_set_power(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- if (vwrq->disabled) {
- if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
- return -EINVAL;
- }
- local->config.powerSaveMode = POWERSAVE_CAM;
- local->config.rmode &= 0xFF00;
- local->config.rmode |= RXMODE_BC_MC_ADDR;
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
- local->config.fastListenDelay = (vwrq->value + 500) / 1024;
- local->config.powerSaveMode = POWERSAVE_PSPCAM;
- local->need_commit = 1;
- } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
- local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
- local->config.powerSaveMode = POWERSAVE_PSPCAM;
- local->need_commit = 1;
- }
- switch (vwrq->flags & IW_POWER_MODE) {
- case IW_POWER_UNICAST_R:
- if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
- return -EINVAL;
- }
- local->config.rmode &= 0xFF00;
- local->config.rmode |= RXMODE_ADDR;
- local->need_commit = 1;
- break;
- case IW_POWER_ALL_R:
- if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
- return -EINVAL;
- }
- local->config.rmode &= 0xFF00;
- local->config.rmode |= RXMODE_BC_MC_ADDR;
- local->need_commit = 1;
- case IW_POWER_ON:
- break;
- default:
- return -EINVAL;
- }
- // Note : we may want to factor local->need_commit here
- // Note2 : may also want to factor RXMODE_RFMON test
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Power Management
- */
- static int airo_get_power(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- int mode = local->config.powerSaveMode;
- if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
- return 0;
- if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
- vwrq->value = (int)local->config.fastListenDelay * 1024;
- vwrq->flags = IW_POWER_TIMEOUT;
- } else {
- vwrq->value = (int)local->config.fastListenInterval * 1024;
- vwrq->flags = IW_POWER_PERIOD;
- }
- if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
- vwrq->flags |= IW_POWER_UNICAST_R;
- else
- vwrq->flags |= IW_POWER_ALL_R;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Sensitivity
- */
- static int airo_set_sens(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
- local->need_commit = 1;
- return -EINPROGRESS; /* Call commit handler */
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Sensitivity
- */
- static int airo_get_sens(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- vwrq->value = local->config.rssiThreshold;
- vwrq->disabled = (vwrq->value == 0);
- vwrq->fixed = 1;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get AP List
- * Note : this is deprecated in favor of IWSCAN
- */
- static int airo_get_aplist(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- struct sockaddr *address = (struct sockaddr *) extra;
- struct iw_quality qual[IW_MAX_AP];
- BSSListRid BSSList;
- int i;
- int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
- for (i = 0; i < IW_MAX_AP; i++) {
- if (readBSSListRid(local, loseSync, &BSSList))
- break;
- loseSync = 0;
- memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
- address[i].sa_family = ARPHRD_ETHER;
- if (local->rssi)
- qual[i].level = 0x100 - local->rssi[BSSList.rssi].rssidBm;
- else
- qual[i].level = (BSSList.rssi + 321) / 2;
- qual[i].qual = qual[i].noise = 0;
- qual[i].updated = 2;
- if (BSSList.index == 0xffff)
- break;
- }
- if (!i) {
- StatusRid status_rid; /* Card status info */
- readStatusRid(local, &status_rid);
- for (i = 0;
- i < min(IW_MAX_AP, 4) &&
- (status_rid.bssid[i][0]
- & status_rid.bssid[i][1]
- & status_rid.bssid[i][2]
- & status_rid.bssid[i][3]
- & status_rid.bssid[i][4]
- & status_rid.bssid[i][5])!=-1 &&
- (status_rid.bssid[i][0]
- | status_rid.bssid[i][1]
- | status_rid.bssid[i][2]
- | status_rid.bssid[i][3]
- | status_rid.bssid[i][4]
- | status_rid.bssid[i][5]);
- i++) {
- memcpy(address[i].sa_data,
- status_rid.bssid[i], ETH_ALEN);
- address[i].sa_family = ARPHRD_ETHER;
- }
- } else {
- dwrq->flags = 1; /* Should be define'd */
- memcpy(extra + sizeof(struct sockaddr)*i,
- &qual, sizeof(struct iw_quality)*i);
- }
- dwrq->length = i;
- return 0;
- }
- #if WIRELESS_EXT > 13
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : Initiate Scan
- */
- static int airo_set_scan(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
- {
- struct airo_info *ai = dev->priv;
- Cmd cmd;
- Resp rsp;
- /* Note : you may have realised that, as this is a SET operation,
- * this is priviledged and therefore a normal user can't
- * perform scanning.
- * This is not an error, while the device perform scanning,
- * traffic doesn't flow, so it's a perfect DoS...
- * Jean II */
- /* Initiate a scan command */
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd=CMD_LISTBSS;
- if (down_interruptible(&ai->sem))
- return -ERESTARTSYS;
- issuecommand(ai, &cmd, &rsp);
- ai->scan_timestamp = jiffies;
- up(&ai->sem);
- /* At this point, just return to the user. */
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Translate scan data returned from the card to a card independant
- * format that the Wireless Tools will understand - Jean II
- */
- static inline char *airo_translate_scan(struct net_device *dev,
- char *current_ev,
- char *end_buf,
- BSSListRid *list)
- {
- struct airo_info *ai = dev->priv;
- struct iw_event iwe; /* Temporary buffer */
- u16 capabilities;
- char * current_val; /* For rates */
- int i;
- /* First entry *MUST* be the AP MAC address */
- iwe.cmd = SIOCGIWAP;
- iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
- memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
- current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
- /* Other entries will be displayed in the order we give them */
- /* Add the ESSID */
- iwe.u.data.length = list->ssidLen;
- if(iwe.u.data.length > 32)
- iwe.u.data.length = 32;
- iwe.cmd = SIOCGIWESSID;
- iwe.u.data.flags = 1;
- current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, list->ssid);
- /* Add mode */
- iwe.cmd = SIOCGIWMODE;
- capabilities = le16_to_cpu(list->cap);
- if(capabilities & (CAP_ESS | CAP_IBSS)) {
- if(capabilities & CAP_ESS)
- iwe.u.mode = IW_MODE_INFRA;
- else
- iwe.u.mode = IW_MODE_ADHOC;
- current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
- }
- /* Add frequency */
- iwe.cmd = SIOCGIWFREQ;
- iwe.u.freq.m = le16_to_cpu(list->dsChannel);
- iwe.u.freq.m = frequency_list[iwe.u.freq.m] * 100000;
- iwe.u.freq.e = 1;
- current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
- /* Add quality statistics */
- iwe.cmd = IWEVQUAL;
- if (ai->rssi)
- iwe.u.qual.level = 0x100 - ai->rssi[list->rssi].rssidBm;
- else
- iwe.u.qual.level = (list->rssi + 321) / 2;
- iwe.u.qual.noise = 0;
- iwe.u.qual.qual = 0;
- current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
- /* Add encryption capability */
- iwe.cmd = SIOCGIWENCODE;
- if(capabilities & CAP_PRIVACY)
- iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
- else
- iwe.u.data.flags = IW_ENCODE_DISABLED;
- iwe.u.data.length = 0;
- current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, list->ssid);
- /* Rate : stuffing multiple values in a single event require a bit
- * more of magic - Jean II */
- current_val = current_ev + IW_EV_LCP_LEN;
- iwe.cmd = SIOCGIWRATE;
- /* Those two flags are ignored... */
- iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
- /* Max 8 values */
- for(i = 0 ; i < 8 ; i++) {
- /* NULL terminated */
- if(list->rates[i] == 0)
- break;
- /* Bit rate given in 500 kb/s units (+ 0x80) */
- iwe.u.bitrate.value = ((list->rates[i] & 0x7f) * 500000);
- /* Add new value to event */
- current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
- }
- /* Check if we added any event */
- if((current_val - current_ev) > IW_EV_LCP_LEN)
- current_ev = current_val;
- /* The other data in the scan result are not really
- * interesting, so for now drop it - Jean II */
- return current_ev;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : Read Scan Results
- */
- static int airo_get_scan(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *ai = dev->priv;
- BSSListRid BSSList;
- int rc;
- char *current_ev = extra;
- /* When we are associated again, the scan has surely finished.
- * Just in case, let's make sure enough time has elapsed since
- * we started the scan. - Javier */
- if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
- /* Important note : we don't want to block the caller
- * until results are ready for various reasons.
- * First, managing wait queues is complex and racy
- * (there may be multiple simultaneous callers).
- * Second, we grab some rtnetlink lock before comming
- * here (in dev_ioctl()).
- * Third, the caller can wait on the Wireless Event
- * - Jean II */
- return -EAGAIN;
- }
- ai->scan_timestamp = 0;
- /* There's only a race with proc_BSSList_open(), but its
- * consequences are begnign. So I don't bother fixing it - Javier */
- /* Try to read the first entry of the scan result */
- rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList));
- if((rc) || (BSSList.index == 0xffff)) {
- /* Client error, no scan results...
- * The caller need to restart the scan. */
- return -ENODATA;
- }
- /* Read and parse all entries */
- while((!rc) && (BSSList.index != 0xffff)) {
- /* Translate to WE format this entry */
- current_ev = airo_translate_scan(dev, current_ev,
- extra + IW_SCAN_MAX_DATA,
- &BSSList);
- /* Read next entry */
- rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
- &BSSList, sizeof(BSSList));
- }
- /* Length of data */
- dwrq->length = (current_ev - extra);
- dwrq->flags = 0; /* todo */
- return 0;
- }
- #endif /* WIRELESS_EXT > 13 */
- #ifdef WIRELESS_SPY
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : set Spy List
- */
- static int airo_set_spy(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- struct sockaddr *address = (struct sockaddr *) extra;
- /* Disable spy while we copy the addresses.
- * As we don't disable interrupts, we need to do this to avoid races */
- local->spy_number = 0;
- if (dwrq->length > 0) {
- int i;
- /* Copy addresses */
- for (i = 0; i < dwrq->length; i++)
- memcpy(local->spy_address[i], address[i].sa_data, ETH_ALEN);
- /* Reset stats */
- memset(local->spy_stat, 0, sizeof(struct iw_quality) * IW_MAX_SPY);
- }
- /* Enable addresses */
- local->spy_number = dwrq->length;
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Wireless Handler : get Spy List
- */
- static int airo_get_spy(struct net_device *dev,
- struct iw_request_info *info,
- struct iw_point *dwrq,
- char *extra)
- {
- struct airo_info *local = dev->priv;
- struct sockaddr *address = (struct sockaddr *) extra;
- int i;
- dwrq->length = local->spy_number;
- /* Copy addresses. */
- for(i = 0; i < local->spy_number; i++) {
- memcpy(address[i].sa_data, local->spy_address[i], ETH_ALEN);
- address[i].sa_family = AF_UNIX;
- }
- /* Copy stats to the user buffer (just after). */
- if(local->spy_number > 0)
- memcpy(extra + (sizeof(struct sockaddr) * local->spy_number),
- local->spy_stat, sizeof(struct iw_quality) * local->spy_number);
- /* Reset updated flags. */
- for (i=0; i<local->spy_number; i++)
- local->spy_stat[i].updated = 0;
- return 0;
- }
- #endif /* WIRELESS_SPY */
- /*------------------------------------------------------------------*/
- /*
- * Commit handler : called after a bunch of SET operations
- */
- static int airo_config_commit(struct net_device *dev,
- struct iw_request_info *info, /* NULL */
- void *zwrq, /* NULL */
- char *extra) /* NULL */
- {
- struct airo_info *local = dev->priv;
- Resp rsp;
- if (!local->need_commit)
- return 0;
- /* Some of the "SET" function may have modified some of the
- * parameters. It's now time to commit them in the card */
- disable_MAC(local);
- writeConfigRid(local);
- enable_MAC(local, &rsp);
- return 0;
- }
- /*------------------------------------------------------------------*/
- /*
- * Structures to export the Wireless Handlers
- */
- static const struct iw_priv_args airo_private_args[] = {
- /*{ cmd, set_args, get_args, name } */
- { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
- IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
- { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
- IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
- };
- #if WIRELESS_EXT > 12
- static const iw_handler airo_handler[] =
- {
- (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
- (iw_handler) airo_get_name, /* SIOCGIWNAME */
- (iw_handler) NULL, /* SIOCSIWNWID */
- (iw_handler) NULL, /* SIOCGIWNWID */
- (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
- (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
- (iw_handler) airo_set_mode, /* SIOCSIWMODE */
- (iw_handler) airo_get_mode, /* SIOCGIWMODE */
- (iw_handler) airo_set_sens, /* SIOCSIWSENS */
- (iw_handler) airo_get_sens, /* SIOCGIWSENS */
- (iw_handler) NULL, /* SIOCSIWRANGE */
- (iw_handler) airo_get_range, /* SIOCGIWRANGE */
- (iw_handler) NULL, /* SIOCSIWPRIV */
- (iw_handler) NULL, /* SIOCGIWPRIV */
- (iw_handler) NULL, /* SIOCSIWSTATS */
- (iw_handler) NULL, /* SIOCGIWSTATS */
- #ifdef WIRELESS_SPY
- (iw_handler) airo_set_spy, /* SIOCSIWSPY */
- (iw_handler) airo_get_spy, /* SIOCGIWSPY */
- #else /* WIRELESS_SPY */
- (iw_handler) NULL, /* SIOCSIWSPY */
- (iw_handler) NULL, /* SIOCGIWSPY */
- #endif /* WIRELESS_SPY */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) airo_set_wap, /* SIOCSIWAP */
- (iw_handler) airo_get_wap, /* SIOCGIWAP */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
- #if WIRELESS_EXT > 13
- (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
- (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
- #else /* WIRELESS_EXT > 13 */
- (iw_handler) NULL, /* SIOCSIWSCAN */
- (iw_handler) NULL, /* SIOCGIWSCAN */
- #endif /* WIRELESS_EXT > 13 */
- (iw_handler) airo_set_essid, /* SIOCSIWESSID */
- (iw_handler) airo_get_essid, /* SIOCGIWESSID */
- (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
- (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) airo_set_rate, /* SIOCSIWRATE */
- (iw_handler) airo_get_rate, /* SIOCGIWRATE */
- (iw_handler) airo_set_rts, /* SIOCSIWRTS */
- (iw_handler) airo_get_rts, /* SIOCGIWRTS */
- (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
- (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
- (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
- (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
- (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
- (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
- (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
- (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
- (iw_handler) airo_set_power, /* SIOCSIWPOWER */
- (iw_handler) airo_get_power, /* SIOCGIWPOWER */
- };
- /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
- * We want to force the use of the ioctl code, because those can't be
- * won't work the iw_handler code (because they simultaneously read
- * and write data and iw_handler can't do that).
- * Note that it's perfectly legal to read/write on a single ioctl command,
- * you just can't use iwpriv and need to force it via the ioctl handler.
- * Jean II */
- static const iw_handler airo_private_handler[] =
- {
- NULL, /* SIOCIWFIRSTPRIV */
- };
- static const struct iw_handler_def airo_handler_def =
- {
- num_standard: sizeof(airo_handler)/sizeof(iw_handler),
- num_private: sizeof(airo_private_handler)/sizeof(iw_handler),
- num_private_args: sizeof(airo_private_args)/sizeof(struct iw_priv_args),
- standard: (iw_handler *) airo_handler,
- private: (iw_handler *) airo_private_handler,
- private_args: (struct iw_priv_args *) airo_private_args,
- };
- #endif /* WIRELESS_EXT > 12 */
- #endif /* WIRELESS_EXT */
- /*
- * This defines the configuration part of the Wireless Extensions
- * Note : irq and spinlock protection will occur in the subroutines
- *
- * TODO :
- * o Check input value more carefully and fill correct values in range
- * o Test and shakeout the bugs (if any)
- *
- * Jean II
- *
- * Javier Achirica did a great job of merging code from the unnamed CISCO
- * developer that added support for flashing the card.
- */
- static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
- {
- int rc = 0;
- #if defined(WIRELESS_EXT) && WIRELESS_EXT < 13
- struct iwreq *wrq = (struct iwreq *) rq;
- #endif /* WIRELESS_EXT < 13 */
- switch (cmd) {
- /* WE 13 and higher will use airo_handler_def */
- #if defined(WIRELESS_EXT) && WIRELESS_EXT < 13
- case SIOCGIWNAME: // Get name
- airo_get_name(dev, NULL, (char *) &(wrq->u.name), NULL);
- break;
- case SIOCSIWFREQ: // Set frequency/channel
- rc = airo_set_freq(dev, NULL, &(wrq->u.freq), NULL);
- break;
- case SIOCGIWFREQ: // Get frequency/channel
- rc = airo_get_freq(dev, NULL, &(wrq->u.freq), NULL);
- break;
- case SIOCSIWESSID: // Set desired network name (ESSID)
- {
- char essidbuf[IW_ESSID_MAX_SIZE+1];
- if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
- rc = -E2BIG;
- break;
- }
- if (copy_from_user(essidbuf, wrq->u.essid.pointer,
- wrq->u.essid.length)) {
- rc = -EFAULT;
- break;
- }
- rc = airo_set_essid(dev, NULL,
- &(wrq->u.essid), essidbuf);
- }
- break;
- case SIOCGIWESSID: // Get current network name (ESSID)
- {
- char essidbuf[IW_ESSID_MAX_SIZE+1];
- if (wrq->u.essid.pointer)
- rc = airo_get_essid(dev, NULL,
- &(wrq->u.essid), essidbuf);
- if ( copy_to_user(wrq->u.essid.pointer,
- essidbuf,
- wrq->u.essid.length) )
- rc = -EFAULT;
- }
- break;
- case SIOCSIWAP:
- rc = airo_set_wap(dev, NULL, &(wrq->u.ap_addr), NULL);
- break;
- case SIOCGIWAP: // Get current Access Point (BSSID)
- rc = airo_get_wap(dev, NULL, &(wrq->u.ap_addr), NULL);
- break;
- case SIOCSIWNICKN: // Set desired station name
- {
- char nickbuf[IW_ESSID_MAX_SIZE+1];
- if (wrq->u.data.length > IW_ESSID_MAX_SIZE) {
- rc = -E2BIG;
- break;
- }
- if (copy_from_user(nickbuf, wrq->u.data.pointer,
- wrq->u.data.length)) {
- rc = -EFAULT;
- break;
- }
- rc = airo_set_nick(dev, NULL,
- &(wrq->u.data), nickbuf);
- }
- break;
- case SIOCGIWNICKN: // Get current station name
- {
- char nickbuf[IW_ESSID_MAX_SIZE+1];
- if (wrq->u.data.pointer)
- rc = airo_get_nick(dev, NULL,
- &(wrq->u.data), nickbuf);
- if ( copy_to_user(wrq->u.data.pointer,
- nickbuf,
- wrq->u.data.length) )
- rc = -EFAULT;
- }
- break;
- case SIOCSIWRATE: // Set the desired bit-rate
- rc = airo_set_rate(dev, NULL, &(wrq->u.bitrate), NULL);
- break;
- case SIOCGIWRATE: // Get the current bit-rate
- rc = airo_get_rate(dev, NULL, &(wrq->u.bitrate), NULL);
- break;
- case SIOCSIWRTS: // Set the desired RTS threshold
- rc = airo_set_rts(dev, NULL, &(wrq->u.rts), NULL);
- break;
- case SIOCGIWRTS: // Get the current RTS threshold
- rc = airo_get_rts(dev, NULL, &(wrq->u.rts), NULL);
- break;
- case SIOCSIWFRAG: // Set the desired fragmentation threshold
- rc = airo_set_frag(dev, NULL, &(wrq->u.frag), NULL);
- break;
- case SIOCGIWFRAG: // Get the current fragmentation threshold
- rc = airo_get_frag(dev, NULL, &(wrq->u.frag), NULL);
- break;
- case SIOCSIWMODE: // Set mode of operation
- rc = airo_set_mode(dev, NULL, &(wrq->u.mode), NULL);
- break;
- case SIOCGIWMODE: // Get mode of operation
- rc = airo_get_mode(dev, NULL, &(wrq->u.mode), NULL);
- break;
- case SIOCSIWENCODE: // Set WEP keys and mode
- {
- char keybuf[MAX_KEY_SIZE];
- if (wrq->u.encoding.pointer) {
- /* We actually have a key to set */
- if (wrq->u.encoding.length > MAX_KEY_SIZE) {
- rc = -E2BIG;
- break;
- }
- if (copy_from_user(keybuf,
- wrq->u.encoding.pointer,
- wrq->u.encoding.length)) {
- rc = -EFAULT;
- break;
- }
- } else if (wrq->u.encoding.length != 0) {
- rc = -EINVAL;
- break;
- }
- rc = airo_set_encode(dev, NULL,
- &(wrq->u.encoding), keybuf);
- }
- break;
- case SIOCGIWENCODE: // Get the WEP keys and mode
- // Only super-user can see WEP key
- // Note : this is needed only for very old versions of WE
- if (!capable(CAP_NET_ADMIN)) {
- rc = -EPERM;
- break;
- }
- {
- char keybuf[MAX_KEY_SIZE];
- rc = airo_get_encode(dev, NULL,
- &(wrq->u.encoding), keybuf);
- if (wrq->u.encoding.pointer) {
- if (copy_to_user(wrq->u.encoding.pointer,
- keybuf,
- wrq->u.encoding.length))
- rc = -EFAULT;
- }
- }
- break;
- case SIOCGIWTXPOW: // Get the current Tx-Power
- rc=airo_get_txpow(dev, NULL, &(wrq->u.txpower), NULL);
- break;
- case SIOCSIWTXPOW:
- rc=airo_set_txpow(dev, NULL, &(wrq->u.txpower), NULL);
- break;
- case SIOCSIWRETRY:
- rc=airo_set_retry(dev, NULL, &(wrq->u.retry), NULL);
- break;
- case SIOCGIWRETRY:
- rc=airo_get_retry(dev, NULL, &(wrq->u.retry), NULL);
- break;
- case SIOCGIWRANGE: // Get range of parameters
- {
- struct iw_range range;
- rc = airo_get_range(dev, NULL,
- &(wrq->u.data), (char *) &range);
- if (copy_to_user(wrq->u.data.pointer, &range,
- sizeof(struct iw_range)))
- rc = -EFAULT;
- }
- break;
- case SIOCGIWPOWER:
- rc=airo_get_power(dev, NULL, &(wrq->u.power), NULL);
- break;
- case SIOCSIWPOWER:
- rc=airo_set_power(dev, NULL, &(wrq->u.power), NULL);
- break;
- case SIOCGIWSENS:
- rc = airo_get_sens(dev, NULL, &(wrq->u.sens), NULL);
- break;
- case SIOCSIWSENS:
- rc = airo_set_sens(dev, NULL, &(wrq->u.sens), NULL);
- break;
- case SIOCGIWAPLIST:
- {
- char buffer[IW_MAX_AP * (sizeof(struct sockaddr) +
- sizeof(struct iw_quality))];
- if (wrq->u.data.pointer) {
- rc = airo_get_aplist(dev, NULL,
- &(wrq->u.data), buffer);
- if (copy_to_user(wrq->u.data.pointer,
- buffer,
- (wrq->u.data.length *
- (sizeof(struct sockaddr) +
- sizeof(struct iw_quality)))
- ))
- rc = -EFAULT;
- }
- }
- break;
- #ifdef WIRELESS_SPY
- case SIOCSIWSPY: // Set the spy list
- {
- struct sockaddr address[IW_MAX_SPY];
- /* Check the number of addresses */
- if (wrq->u.data.length > IW_MAX_SPY) {
- rc = -E2BIG;
- break;
- }
- /* Get the data in the driver */
- if (wrq->u.data.pointer) {
- if (copy_from_user((char *) address,
- wrq->u.data.pointer,
- sizeof(struct sockaddr) *
- wrq->u.data.length)) {
- rc = -EFAULT;
- break;
- }
- } else if (wrq->u.data.length != 0) {
- rc = -EINVAL;
- break;
- }
- rc=airo_set_spy(dev, NULL, &(wrq->u.data),
- (char *) address);
- }
- break;
- case SIOCGIWSPY: // Get the spy list
- {
- char buffer[IW_MAX_SPY * (sizeof(struct sockaddr) +
- sizeof(struct iw_quality))];
- if (wrq->u.data.pointer) {
- rc = airo_get_spy(dev, NULL,
- &(wrq->u.data), buffer);
- if (copy_to_user(wrq->u.data.pointer,
- buffer,
- (wrq->u.data.length *
- (sizeof(struct sockaddr) +
- sizeof(struct iw_quality)))
- ))
- rc = -EFAULT;
- }
- }
- break;
- #endif /* WIRELESS_SPY */
- #ifdef CISCO_EXT
- case SIOCGIWPRIV:
- if(wrq->u.data.pointer) {
- /* Set the number of ioctl available */
- wrq->u.data.length = sizeof(airo_private_args) / sizeof( airo_private_args[0]);
- /* Copy structure to the user buffer */
- if(copy_to_user(wrq->u.data.pointer,
- (u_char *) airo_private_args,
- sizeof(airo_private_args)))
- rc = -EFAULT;
- }
- break;
- #endif /* CISCO_EXT */
- #endif /* WIRELESS_EXT < 13 */
- #ifdef CISCO_EXT
- case AIROIDIFC:
- #ifdef AIROOLDIDIFC
- case AIROOLDIDIFC:
- #endif
- {
- int val = AIROMAGIC;
- aironet_ioctl com;
- if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
- rc = -EFAULT;
- else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
- rc = -EFAULT;
- }
- break;
- case AIROIOCTL:
- #ifdef AIROOLDIOCTL
- case AIROOLDIOCTL:
- #endif
- /* Get the command struct and hand it off for evaluation by
- * the proper subfunction
- */
- {
- aironet_ioctl com;
- if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
- rc = -EFAULT;
- break;
- }
- /* Seperate R/W functions bracket legality here
- */
- if ( com.command <= AIROGMICSTATS )
- rc = readrids(dev,&com);
- else if ( com.command >= AIROPCAP && com.command <= AIROPLEAPUSR )
- rc = writerids(dev,&com);
- else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
- rc = flashcard(dev,&com);
- else
- rc = -EINVAL; /* Bad command in ioctl */
- }
- break;
- #endif /* CISCO_EXT */
- // All other calls are currently unsupported
- default:
- rc = -EOPNOTSUPP;
- }
- #if defined(WIRELESS_EXT) && WIRELESS_EXT < 13
- /* WE 13 and higher will use airo_config_commit */
- /* Some of the "SET" function may have modified some of the
- * parameters. It's now time to commit them in the card */
- airo_config_commit(dev, NULL, NULL, NULL);
- if (rc == -EINPROGRESS)
- return 0;
- #endif /* WIRELESS_EXT < 13 */
- return rc;
- }
- #ifdef WIRELESS_EXT
- /*
- * Get the Wireless stats out of the driver
- * Note : irq and spinlock protection will occur in the subroutines
- *
- * TODO :
- * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
- * o Find the noise level
- *
- * Jean
- */
- struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
- {
- struct airo_info *local = dev->priv;
- StatusRid status_rid;
- StatsRid stats_rid;
- u32 *vals = stats_rid.vals;
- /* Get stats out of the card */
- readStatusRid(local, &status_rid);
- readStatsRid(local, &stats_rid, RID_STATS);
- /* The status */
- local->wstats.status = status_rid.mode;
- /* Signal quality and co. But where is the noise level ??? */
- local->wstats.qual.qual = status_rid.signalQuality;
- if (local->rssi)
- local->wstats.qual.level = 0x100 - local->rssi[status_rid.sigQuality].rssidBm;
- else
- local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
- local->wstats.qual.noise = 0;
- local->wstats.qual.updated = 3;
- /* Packets discarded in the wireless adapter due to wireless
- * specific problems */
- local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
- local->wstats.discard.code = vals[6];/* RxWepErr */
- local->wstats.discard.fragment = vals[30];
- local->wstats.discard.retries = vals[10];
- local->wstats.discard.misc = vals[1] + vals[32];
- local->wstats.miss.beacon = vals[34];
- return &local->wstats;
- }
- #endif /* WIRELESS_EXT */
- #ifdef CISCO_EXT
- /*
- * This just translates from driver IOCTL codes to the command codes to
- * feed to the radio's host interface. Things can be added/deleted
- * as needed. This represents the READ side of control I/O to
- * the card
- */
- static int readrids(struct net_device *dev, aironet_ioctl *comp) {
- unsigned short ridcode;
- unsigned char iobuf[2048];
- struct airo_info *ai = dev->priv;
- if (ai->flags & FLAG_FLASHING)
- return -EIO;
- switch(comp->command)
- {
- case AIROGCAP: ridcode = RID_CAPABILITIES; break;
- case AIROGCFG: writeConfigRid (ai);
- ridcode = RID_CONFIG; break;
- case AIROGSLIST: ridcode = RID_SSID; break;
- case AIROGVLIST: ridcode = RID_APLIST; break;
- case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
- case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
- case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
- /* Only super-user can read WEP keys */
- if (!capable(CAP_NET_ADMIN))
- return -EPERM;
- break;
- case AIROGWEPKNV: ridcode = RID_WEP_PERM;
- /* Only super-user can read WEP keys */
- if (!capable(CAP_NET_ADMIN))
- return -EPERM;
- break;
- case AIROGSTAT: ridcode = RID_STATUS; break;
- case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
- case AIROGSTATSC32: ridcode = RID_STATS; break;
- case AIROGMICSTATS:
- if (copy_to_user(comp->data, &ai->micstats,
- min((int)comp->len,(int)sizeof(ai->micstats))))
- return -EFAULT;
- return 0;
- default:
- return -EINVAL;
- break;
- }
- PC4500_readrid(ai,ridcode,iobuf,sizeof(iobuf));
- /* get the count of bytes in the rid docs say 1st 2 bytes is it.
- * then return it to the user
- * 9/22/2000 Honor user given length
- */
- if (copy_to_user(comp->data, iobuf,
- min((int)comp->len, (int)sizeof(iobuf))))
- return -EFAULT;
- return 0;
- }
- /*
- * Danger Will Robinson write the rids here
- */
- static int writerids(struct net_device *dev, aironet_ioctl *comp) {
- struct airo_info *ai = dev->priv;
- int ridcode, enabled;
- Resp rsp;
- static int (* writer)(struct airo_info *, u16 rid, const void *, int);
- unsigned char iobuf[2048];
- /* Only super-user can write RIDs */
- if (!capable(CAP_NET_ADMIN))
- return -EPERM;
- if (ai->flags & FLAG_FLASHING)
- return -EIO;
- ridcode = 0;
- writer = do_writerid;
- switch(comp->command)
- {
- case AIROPSIDS: ridcode = RID_SSID; break;
- case AIROPCAP: ridcode = RID_CAPABILITIES; break;
- case AIROPAPLIST: ridcode = RID_APLIST; break;
- case AIROPCFG: ai->config.len = 0;
- ridcode = RID_CONFIG; break;
- case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
- case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
- case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
- case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
- break;
- /* this is not really a rid but a command given to the card
- * same with MAC off
- */
- case AIROPMACON:
- if (enable_MAC(ai, &rsp) != 0)
- return -EIO;
- return 0;
- /*
- * Evidently this code in the airo driver does not get a symbol
- * as disable_MAC. it's probably so short the compiler does not gen one.
- */
- case AIROPMACOFF:
- disable_MAC(ai);
- return 0;
- /* This command merely clears the counts does not actually store any data
- * only reads rid. But as it changes the cards state, I put it in the
- * writerid routines.
- */
- case AIROPSTCLR:
- PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,sizeof(iobuf));
- enabled = ai->micstats.enabled;
- memset(&ai->micstats,0,sizeof(ai->micstats));
- ai->micstats.enabled = enabled;
- if (copy_to_user(comp->data, iobuf,
- min((int)comp->len, (int)sizeof(iobuf))))
- return -EFAULT;
- return 0;
- default:
- return -EOPNOTSUPP; /* Blarg! */
- }
- if(comp->len > sizeof(iobuf))
- return -EINVAL;
- if (copy_from_user(iobuf,comp->data,comp->len))
- return -EFAULT;
- if (comp->command == AIROPCFG) {
- ConfigRid *cfg = (ConfigRid *)iobuf;
- if (ai->flags & FLAG_MIC_CAPABLE)
- cfg->opmode |= MODE_MIC;
- if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
- ai->flags |= FLAG_ADHOC;
- else
- ai->flags &= ~FLAG_ADHOC;
- }
- if((*writer)(ai, ridcode, iobuf,comp->len))
- return -EIO;
- return 0;
- }
- /*****************************************************************************
- * Ancillary flash / mod functions much black magic lurkes here *
- *****************************************************************************
- */
- /*
- * Flash command switch table
- */
- int flashcard(struct net_device *dev, aironet_ioctl *comp) {
- int z;
- int cmdreset(struct airo_info *);
- int setflashmode(struct airo_info *);
- int flashgchar(struct airo_info *,int,int);
- int flashpchar(struct airo_info *,int,int);
- int flashputbuf(struct airo_info *);
- int flashrestart(struct airo_info *,struct net_device *);
- /* Only super-user can modify flash */
- if (!capable(CAP_NET_ADMIN))
- return -EPERM;
- switch(comp->command)
- {
- case AIROFLSHRST:
- return cmdreset((struct airo_info *)dev->priv);
- case AIROFLSHSTFL:
- if (!((struct airo_info *)dev->priv)->flash &&
- (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL)
- return -ENOMEM;
- return setflashmode((struct airo_info *)dev->priv);
- case AIROFLSHGCHR: /* Get char from aux */
- if(comp->len != sizeof(int))
- return -EINVAL;
- if (copy_from_user(&z,comp->data,comp->len))
- return -EFAULT;
- return flashgchar((struct airo_info *)dev->priv,z,8000);
- case AIROFLSHPCHR: /* Send char to card. */
- if(comp->len != sizeof(int))
- return -EINVAL;
- if (copy_from_user(&z,comp->data,comp->len))
- return -EFAULT;
- return flashpchar((struct airo_info *)dev->priv,z,8000);
- case AIROFLPUTBUF: /* Send 32k to card */
- if (!((struct airo_info *)dev->priv)->flash)
- return -ENOMEM;
- if(comp->len > FLASHSIZE)
- return -EINVAL;
- if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len))
- return -EFAULT;
- flashputbuf((struct airo_info *)dev->priv);
- return 0;
- case AIRORESTART:
- if(flashrestart((struct airo_info *)dev->priv,dev))
- return -EIO;
- return 0;
- }
- return -EINVAL;
- }
- #define FLASH_COMMAND 0x7e7e
- /*
- * STEP 1)
- * Disable MAC and do soft reset on
- * card.
- */
- int cmdreset(struct airo_info *ai) {
- disable_MAC(ai);
- if(!waitbusy (ai)){
- printk(KERN_INFO "Waitbusy hang before RESETn");
- return -EBUSY;
- }
- OUT4500(ai,COMMAND,CMD_SOFTRESET);
- set_current_state (TASK_UNINTERRUPTIBLE);
- schedule_timeout (HZ); /* WAS 600 12/7/00 */
- if(!waitbusy (ai)){
- printk(KERN_INFO "Waitbusy hang AFTER RESETn");
- return -EBUSY;
- }
- return 0;
- }
- /* STEP 2)
- * Put the card in legendary flash
- * mode
- */
- int setflashmode (struct airo_info *ai) {
- ai->flags |= FLAG_FLASHING;
- OUT4500(ai, SWS0, FLASH_COMMAND);
- OUT4500(ai, SWS1, FLASH_COMMAND);
- if (probe) {
- OUT4500(ai, SWS0, FLASH_COMMAND);
- OUT4500(ai, COMMAND,0x10);
- } else {
- OUT4500(ai, SWS2, FLASH_COMMAND);
- OUT4500(ai, SWS3, FLASH_COMMAND);
- OUT4500(ai, COMMAND,0);
- }
- set_current_state (TASK_UNINTERRUPTIBLE);
- schedule_timeout (HZ/2); /* 500ms delay */
- if(!waitbusy(ai)) {
- ai->flags &= ~FLAG_FLASHING;
- printk(KERN_INFO "Waitbusy hang after setflash moden");
- return -EIO;
- }
- return 0;
- }
- /* Put character to SWS0 wait for dwelltime
- * x 50us for echo .
- */
- int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
- int echo;
- int waittime;
- byte |= 0x8000;
- if(dwelltime == 0 )
- dwelltime = 200;
- waittime=dwelltime;
- /* Wait for busy bit d15 to go false indicating buffer empty */
- while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
- udelay (50);
- waittime -= 50;
- }
- /* timeout for busy clear wait */
- if(waittime <= 0 ){
- printk(KERN_INFO "flash putchar busywait timeout! n");
- return -EBUSY;
- }
- /* Port is clear now write byte and wait for it to echo back */
- do {
- OUT4500(ai,SWS0,byte);
- udelay(50);
- dwelltime -= 50;
- echo = IN4500(ai,SWS1);
- } while (dwelltime >= 0 && echo != byte);
- OUT4500(ai,SWS1,0);
- return (echo == byte) ? 0 : -EIO;
- }
- /*
- * Get a character from the card matching matchbyte
- * Step 3)
- */
- int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
- int rchar;
- unsigned char rbyte=0;
- do {
- rchar = IN4500(ai,SWS1);
- if(dwelltime && !(0x8000 & rchar)){
- dwelltime -= 10;
- mdelay(10);
- continue;
- }
- rbyte = 0xff & rchar;
- if( (rbyte == matchbyte) && (0x8000 & rchar) ){
- OUT4500(ai,SWS1,0);
- return 0;
- }
- if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
- break;
- OUT4500(ai,SWS1,0);
- }while(dwelltime > 0);
- return -EIO;
- }
- /*
- * Transfer 32k of firmware data from user buffer to our buffer and
- * send to the card
- */
- int flashputbuf(struct airo_info *ai){
- int nwords;
- /* Write stuff */
- OUT4500(ai,AUXPAGE,0x100);
- OUT4500(ai,AUXOFF,0);
- for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
- OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
- }
- OUT4500(ai,SWS0,0x8000);
- return 0;
- }
- /*
- *
- */
- int flashrestart(struct airo_info *ai,struct net_device *dev){
- int i,status;
- set_current_state (TASK_UNINTERRUPTIBLE);
- schedule_timeout (HZ); /* Added 12/7/00 */
- ai->flags &= ~FLAG_FLASHING;
- status = setup_card(ai, dev->dev_addr);
- for( i = 0; i < MAX_FIDS; i++ ) {
- ai->fids[i] = transmit_allocate( ai, 2312, i >= MAX_FIDS / 2 );
- }
- set_current_state (TASK_UNINTERRUPTIBLE);
- schedule_timeout (HZ); /* Added 12/7/00 */
- return status;
- }
- #endif /* CISCO_EXT */
- /*
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- In addition:
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. The name of the author may not be used to endorse or promote
- products derived from this software without specific prior written
- permission.
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
- */
- module_init(airo_init_module);
- module_exit(airo_cleanup_module);