/* * Print the number of available bitrates for the device */ static int print_bitrate_info(int skfd, char * ifname, char * args[], /* Command line args */ int count) /* Args count */ { struct iwreq wrq; struct iw_range range; int k; char buffer[128]; /* Avoid "Unused parameter" warning */ args = args; count = count; /* Extract range info */ if(iw_get_range_info(skfd, ifname, &range) < 0) fprintf(stderr, "%-8.16s no bit-rate information.\n\n", ifname); else { if((range.num_bitrates > 0) && (range.num_bitrates <= IW_MAX_BITRATES)) { printf("%-8.16s %d available bit-rates :\n", ifname, range.num_bitrates); /* Print them all */ for(k = 0; k < range.num_bitrates; k++) { iw_print_bitrate(buffer, sizeof(buffer), range.bitrate[k]); /* Maybe this should be %10s */ printf("\t %s\n", buffer); } } else printf("%-8.16s unknown bit-rate information.\n", ifname); /* Get current bit rate */ if(iw_get_ext(skfd, ifname, SIOCGIWRATE, &wrq) >= 0) { iw_print_bitrate(buffer, sizeof(buffer), wrq.u.bitrate.value); printf(" Current Bit Rate%c%s\n\n", (wrq.u.bitrate.fixed ? '=' : ':'), buffer); } } return(0); }
static const char * get_bitrate_string(void *arg) { if (iw_get_ext(skfd, arg, SIOCGIWRATE, &wrq) < 0) { xsg_debug("get_bitrate_string: UNKNOWN"); return NULL; } iw_print_bitrate(buffer, sizeof(buffer), wrq.u.bitrate.value); xsg_debug("get_bitrate_string: \"%s\"", buffer); return buffer; }
/* * Print on the screen in a neat fashion all the info we have collected * on a device. */ static void display_info(struct wireless_info * info, char * ifname) { char buffer[128]; /* Temporary buffer */ /* One token is more of less 5 characters, 14 tokens per line */ int tokens = 3; /* For name */ /* Display device name and wireless name (name of the protocol used) */ printf("%-8.16s %s ", ifname, info->b.name); /* Display ESSID (extended network), if any */ if(info->b.has_essid) { if(info->b.essid_on) { /* Does it have an ESSID index ? */ if((info->b.essid_on & IW_ENCODE_INDEX) > 1) printf("ESSID:\"%s\" [%d] ", info->b.essid, (info->b.essid_on & IW_ENCODE_INDEX)); else printf("ESSID:\"%s\" ", info->b.essid); } else printf("ESSID:off/any "); } #ifndef WE_ESSENTIAL /* Display NickName (station name), if any */ if(info->has_nickname) printf("Nickname:\"%s\"", info->nickname); #endif /* WE_ESSENTIAL */ /* Formatting */ if(info->b.has_essid || info->has_nickname) { printf("\n "); tokens = 0; } #ifndef WE_ESSENTIAL /* Display Network ID */ if(info->b.has_nwid) { /* Note : should display proper number of digits according to info * in range structure */ if(info->b.nwid.disabled) printf("NWID:off/any "); else printf("NWID:%X ", info->b.nwid.value); tokens +=2; } #endif /* WE_ESSENTIAL */ /* Display the current mode of operation */ if(info->b.has_mode) { printf("Mode:%s ", iw_operation_mode[info->b.mode]); tokens +=3; } /* Display frequency / channel */ if(info->b.has_freq) { double freq = info->b.freq; /* Frequency/channel */ int channel = -1; /* Converted to channel */ /* Some drivers insist of returning channel instead of frequency. * This fixes them up. Note that, driver should still return * frequency, because other tools depend on it. */ if(info->has_range && (freq < KILO)) channel = iw_channel_to_freq((int) freq, &freq, &info->range); /* Display */ iw_print_freq(buffer, sizeof(buffer), freq, -1, info->b.freq_flags); printf("%s ", buffer); tokens +=4; } /* Display the address of the current Access Point */ if(info->has_ap_addr) { /* A bit of clever formatting */ if(tokens > 8) { printf("\n "); tokens = 0; } tokens +=6; /* Oups ! No Access Point in Ad-Hoc mode */ if((info->b.has_mode) && (info->b.mode == IW_MODE_ADHOC)) printf("Cell:"); else printf("Access Point:"); printf(" %s ", iw_sawap_ntop(&info->ap_addr, buffer)); } /* Display the currently used/set bit-rate */ if(info->has_bitrate) { /* A bit of clever formatting */ if(tokens > 11) { printf("\n "); tokens = 0; } tokens +=3; /* Display it */ iw_print_bitrate(buffer, sizeof(buffer), info->bitrate.value); printf("Bit Rate%c%s ", (info->bitrate.fixed ? '=' : ':'), buffer); } #ifndef WE_ESSENTIAL /* Display the Transmit Power */ if(info->has_txpower) { /* A bit of clever formatting */ if(tokens > 11) { printf("\n "); tokens = 0; } tokens +=3; /* Display it */ iw_print_txpower(buffer, sizeof(buffer), &info->txpower); printf("Tx-Power%c%s ", (info->txpower.fixed ? '=' : ':'), buffer); } /* Display sensitivity */ if(info->has_sens) { /* A bit of clever formatting */ if(tokens > 10) { printf("\n "); tokens = 0; } tokens +=4; /* Fixed ? */ printf("Sensitivity%c", info->sens.fixed ? '=' : ':'); if(info->has_range) /* Display in dBm ? */ if(info->sens.value < 0) printf("%d dBm ", info->sens.value); else printf("%d/%d ", info->sens.value, info->range.sensitivity); else printf("%d ", info->sens.value); } #endif /* WE_ESSENTIAL */ printf("\n "); tokens = 0; #ifndef WE_ESSENTIAL /* Display retry limit/lifetime information */ if(info->has_retry) { printf("Retry"); /* Disabled ? */ if(info->retry.disabled) printf(":off"); else { /* Let's check the value and its type */ if(info->retry.flags & IW_RETRY_TYPE) { iw_print_retry_value(buffer, sizeof(buffer), info->retry.value, info->retry.flags, info->range.we_version_compiled); printf("%s", buffer); } /* Let's check if nothing (simply on) */ if(info->retry.flags == IW_RETRY_ON) printf(":on"); } printf(" "); tokens += 5; /* Between 3 and 5, depend on flags */ } /* Display the RTS threshold */ if(info->has_rts) { /* Disabled ? */ if(info->rts.disabled) printf("RTS thr:off "); else { /* Fixed ? */ printf("RTS thr%c%d B ", info->rts.fixed ? '=' : ':', info->rts.value); } tokens += 3; } /* Display the fragmentation threshold */ if(info->has_frag) { /* A bit of clever formatting */ if(tokens > 10) { printf("\n "); tokens = 0; } tokens +=4; /* Disabled ? */ if(info->frag.disabled) printf("Fragment thr:off"); else { /* Fixed ? */ printf("Fragment thr%c%d B ", info->frag.fixed ? '=' : ':', info->frag.value); } } /* Formating */ if(tokens > 0) printf("\n "); #endif /* WE_ESSENTIAL */ /* Display encryption information */ /* Note : we display only the "current" key, use iwlist to list all keys */ if(info->b.has_key) { printf("Encryption key:"); if((info->b.key_flags & IW_ENCODE_DISABLED) || (info->b.key_size == 0)) printf("off"); else { /* Display the key */ iw_print_key(buffer, sizeof(buffer), info->b.key, info->b.key_size, info->b.key_flags); printf("%s", buffer); /* Other info... */ if((info->b.key_flags & IW_ENCODE_INDEX) > 1) printf(" [%d]", info->b.key_flags & IW_ENCODE_INDEX); if(info->b.key_flags & IW_ENCODE_RESTRICTED) printf(" Security mode:restricted"); if(info->b.key_flags & IW_ENCODE_OPEN) printf(" Security mode:open"); } printf("\n "); } /* Display Power Management information */ /* Note : we display only one parameter, period or timeout. If a device * (such as HiperLan) has both, the user need to use iwlist... */ if(info->has_power) /* I hope the device has power ;-) */ { printf("Power Management"); /* Disabled ? */ if(info->power.disabled) printf(":off"); else { /* Let's check the value and its type */ if(info->power.flags & IW_POWER_TYPE) { iw_print_pm_value(buffer, sizeof(buffer), info->power.value, info->power.flags, info->range.we_version_compiled); printf("%s ", buffer); } /* Let's check the mode */ iw_print_pm_mode(buffer, sizeof(buffer), info->power.flags); printf("%s", buffer); /* Let's check if nothing (simply on) */ if(info->power.flags == IW_POWER_ON) printf(":on"); } printf("\n "); } /* Display statistics */ if(info->has_stats) { iw_print_stats(buffer, sizeof(buffer), &info->stats.qual, &info->range, info->has_range); printf("Link %s\n", buffer); if(info->range.we_version_compiled > 11) printf(" Rx invalid nwid:%d Rx invalid crypt:%d Rx invalid frag:%d\n Tx excessive retries:%d Invalid misc:%d Missed beacon:%d\n", info->stats.discard.nwid, info->stats.discard.code, info->stats.discard.fragment, info->stats.discard.retries, info->stats.discard.misc, info->stats.miss.beacon); else printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n", info->stats.discard.nwid, info->stats.discard.code, info->stats.discard.misc); } printf("\n"); }
/* * Print on the screen in a neat fashion all the info we have collected * on a device. */ static void display_info(struct wireless_info * info, char * ifname) { char buffer[128]; /* Temporary buffer */ /* One token is more of less 5 characters, 14 tokens per line */ int tokens = 3; /* For name */ /* Display device name and wireless name (name of the protocol used) */ printf("%-8.8s %s ", ifname, info->name); /* Display ESSID (extended network), if any */ if(info->has_essid) { if(info->essid_on) { /* Does it have an ESSID index ? */ if((info->essid_on & IW_ENCODE_INDEX) > 1) printf("ESSID:\"%s\" [%d] ", info->essid, (info->essid_on & IW_ENCODE_INDEX)); else printf("ESSID:\"%s\" ", info->essid); } else printf("ESSID:off/any "); } /* Display NickName (station name), if any */ if(info->has_nickname) printf("Nickname:\"%s\"", info->nickname); /* Formatting */ if(info->has_essid || info->has_nickname) { printf("\n "); tokens = 0; } /* Display Network ID */ if(info->has_nwid) { /* Note : should display proper number of digit according to info * in range structure */ if(info->nwid.disabled) printf("NWID:off/any "); else printf("NWID:%X ", info->nwid.value); tokens +=2; } /* Display the current mode of operation */ if(info->has_mode) { printf("Mode:%s ", iw_operation_mode[info->mode]); tokens +=3; } /* Display frequency / channel */ if(info->has_freq) { iw_print_freq(buffer, info->freq); printf("%s ", buffer); tokens +=4; } /* Display the address of the current Access Point */ if(info->has_ap_addr) { /* A bit of clever formatting */ if(tokens > 8) { printf("\n "); tokens = 0; } tokens +=6; /* Oups ! No Access Point in Ad-Hoc mode */ if((info->has_mode) && (info->mode == IW_MODE_ADHOC)) printf("Cell:"); else printf("Access Point:"); printf(" %s ", iw_pr_ether(buffer, info->ap_addr.sa_data)); } /* Display the currently used/set bit-rate */ if(info->has_bitrate) { /* A bit of clever formatting */ if(tokens > 11) { printf("\n "); tokens = 0; } tokens +=3; /* Display it */ iw_print_bitrate(buffer, info->bitrate.value); printf("Bit Rate%c%s ", (info->bitrate.fixed ? '=' : ':'), buffer); } #if WIRELESS_EXT > 9 /* Display the Transmit Power */ if(info->has_txpower) { /* A bit of clever formatting */ if(tokens > 11) { printf("\n "); tokens = 0; } tokens +=3; /* Disabled ? */ if(info->txpower.disabled) printf("Tx-Power:off "); else { int dbm; /* Fixed ? */ if(info->txpower.fixed) printf("Tx-Power="); else printf("Tx-Power:"); /* Convert everything to dBm */ if(info->txpower.flags & IW_TXPOW_MWATT) dbm = iw_mwatt2dbm(info->txpower.value); else dbm = info->txpower.value; /* Display */ printf("%d dBm ", dbm); } } #endif /* Display sensitivity */ if(info->has_sens) { /* A bit of clever formatting */ if(tokens > 10) { printf("\n "); tokens = 0; } tokens +=4; /* Fixed ? */ if(info->sens.fixed) printf("Sensitivity="); else printf("Sensitivity:"); if(info->has_range) /* Display in dBm ? */ if(info->sens.value < 0) printf("%d dBm ", info->sens.value); else printf("%d/%d ", info->sens.value, info->range.sensitivity); else printf("%d ", info->sens.value); } printf("\n "); tokens = 0; #if WIRELESS_EXT > 10 /* Display retry limit/lifetime information */ if(info->has_retry) { printf("Retry"); /* Disabled ? */ if(info->retry.disabled) printf(":off"); else { /* Let's check the value and its type */ if(info->retry.flags & IW_RETRY_TYPE) { iw_print_retry_value(buffer, info->retry.value, info->retry.flags); printf("%s", buffer); } /* Let's check if nothing (simply on) */ if(info->retry.flags == IW_RETRY_ON) printf(":on"); } printf(" "); tokens += 5; /* Between 3 and 5, depend on flags */ } #endif /* WIRELESS_EXT > 10 */ /* Display the RTS threshold */ if(info->has_rts) { /* Disabled ? */ if(info->rts.disabled) printf("RTS thr:off "); else { /* Fixed ? */ if(info->rts.fixed) printf("RTS thr="); else printf("RTS thr:"); printf("%d B ", info->rts.value); } tokens += 3; } /* Display the fragmentation threshold */ if(info->has_frag) { /* A bit of clever formatting */ if(tokens > 10) { printf("\n "); tokens = 0; } tokens +=4; /* Disabled ? */ if(info->frag.disabled) printf("Fragment thr:off"); else { /* Fixed ? */ if(info->frag.fixed) printf("Fragment thr="); else printf("Fragment thr:"); printf("%d B ", info->frag.value); } } /* Formating */ if(tokens > 0) printf("\n "); /* Display encryption information */ /* Note : we display only the "current" key, use iwlist to list all keys */ if(info->has_key) { printf("Encryption key:"); if((info->key_flags & IW_ENCODE_DISABLED) || (info->key_size == 0)) printf("off\n "); else { /* Display the key */ iw_print_key(buffer, info->key, info->key_size, info->key_flags); printf("%s", buffer); /* Other info... */ if((info->key_flags & IW_ENCODE_INDEX) > 1) printf(" [%d]", info->key_flags & IW_ENCODE_INDEX); if(info->key_flags & IW_ENCODE_RESTRICTED) printf(" Security mode:restricted"); if(info->key_flags & IW_ENCODE_OPEN) printf(" Security mode:open"); printf("\n "); } } /* Display Power Management information */ /* Note : we display only one parameter, period or timeout. If a device * (such as HiperLan) has both, the user need to use iwlist... */ if(info->has_power) /* I hope the device has power ;-) */ { printf("Power Management"); /* Disabled ? */ if(info->power.disabled) printf(":off\n "); else { /* Let's check the value and its type */ if(info->power.flags & IW_POWER_TYPE) { iw_print_pm_value(buffer, info->power.value, info->power.flags); printf("%s ", buffer); } /* Let's check the mode */ iw_print_pm_mode(buffer, info->power.flags); printf("%s", buffer); /* Let's check if nothing (simply on) */ if(info->power.flags == IW_POWER_ON) printf(":on"); printf("\n "); } } /* Display statistics */ if(info->has_stats) { info->stats.qual.updated = 0x0; /* Not that reliable, disable */ iw_print_stats(buffer, &info->stats.qual, &info->range, info->has_range); printf("Link %s\n", buffer); #if WIRELESS_EXT > 11 printf(" Rx invalid nwid:%d Rx invalid crypt:%d Rx invalid frag:%d\n Tx excessive retries:%d Invalid misc:%d Missed beacon:%d\n", info->stats.discard.nwid, info->stats.discard.code, info->stats.discard.fragment, info->stats.discard.retries, info->stats.discard.misc, info->stats.miss.beacon); #else /* WIRELESS_EXT > 11 */ printf(" Rx invalid nwid:%d invalid crypt:%d invalid misc:%d\n", info->stats.discard.nwid, info->stats.discard.code, info->stats.discard.misc); #endif /* WIRELESS_EXT > 11 */ } printf("\n"); }
/* * Print one element from the scanning results */ static inline int print_event_token(struct iw_event * event, /* Extracted token */ struct iw_range * iw_range, /* Range info */ int has_range) { char buffer[128]; /* Temporary buffer */ char buffer2[30]; /* Temporary buffer */ char * prefix = (IW_IS_GET(event->cmd) ? "New" : "Set"); /* Now, let's decode the event */ switch(event->cmd) { /* ----- set events ----- */ /* Events that result from a "SET XXX" operation by the user */ case SIOCSIWNWID: if(event->u.nwid.disabled) printf("Set NWID:off/any\n"); else printf("Set NWID:%X\n", event->u.nwid.value); break; case SIOCSIWFREQ: case SIOCGIWFREQ: { double freq; /* Frequency/channel */ int channel = -1; /* Converted to channel */ freq = iw_freq2float(&(event->u.freq)); if(has_range) { if(freq < KILO) /* Convert channel to frequency if possible */ channel = iw_channel_to_freq((int) freq, &freq, iw_range); else /* Convert frequency to channel if possible */ channel = iw_freq_to_channel(freq, iw_range); } iw_print_freq(buffer, sizeof(buffer), freq, channel, event->u.freq.flags); printf("%s %s\n", prefix, buffer); } break; case SIOCSIWMODE: printf("Set Mode:%s\n", iw_operation_mode[event->u.mode]); break; case SIOCSIWESSID: case SIOCGIWESSID: { char essid[IW_ESSID_MAX_SIZE+1]; memset(essid, '\0', sizeof(essid)); if((event->u.essid.pointer) && (event->u.essid.length)) memcpy(essid, event->u.essid.pointer, event->u.essid.length); if(event->u.essid.flags) { /* Does it have an ESSID index ? */ if((event->u.essid.flags & IW_ENCODE_INDEX) > 1) printf("%s ESSID:\"%s\" [%d]\n", prefix, essid, (event->u.essid.flags & IW_ENCODE_INDEX)); else printf("%s ESSID:\"%s\"\n", prefix, essid); } else printf("%s ESSID:off/any\n", prefix); } break; case SIOCSIWENCODE: { unsigned char key[IW_ENCODING_TOKEN_MAX]; if(event->u.data.pointer) memcpy(key, event->u.data.pointer, event->u.data.length); else event->u.data.flags |= IW_ENCODE_NOKEY; printf("Set Encryption key:"); if(event->u.data.flags & IW_ENCODE_DISABLED) printf("off\n"); else { /* Display the key */ iw_print_key(buffer, sizeof(buffer), key, event->u.data.length, event->u.data.flags); printf("%s", buffer); /* Other info... */ if((event->u.data.flags & IW_ENCODE_INDEX) > 1) printf(" [%d]", event->u.data.flags & IW_ENCODE_INDEX); if(event->u.data.flags & IW_ENCODE_RESTRICTED) printf(" Security mode:restricted"); if(event->u.data.flags & IW_ENCODE_OPEN) printf(" Security mode:open"); printf("\n"); } } break; /* ----- driver events ----- */ /* Events generated by the driver when something important happens */ case SIOCGIWAP: printf("New Access Point/Cell address:%s\n", iw_sawap_ntop(&event->u.ap_addr, buffer)); break; case SIOCGIWSCAN: printf("Scan request completed\n"); break; case IWEVTXDROP: printf("Tx packet dropped:%s\n", iw_saether_ntop(&event->u.addr, buffer)); break; case IWEVCUSTOM: { char custom[IW_CUSTOM_MAX+1]; memset(custom, '\0', sizeof(custom)); if((event->u.data.pointer) && (event->u.data.length)) memcpy(custom, event->u.data.pointer, event->u.data.length); printf("Custom driver event:%s\n", custom); } break; case IWEVREGISTERED: printf("Registered node:%s\n", iw_saether_ntop(&event->u.addr, buffer)); break; case IWEVEXPIRED: printf("Expired node:%s\n", iw_saether_ntop(&event->u.addr, buffer)); break; case SIOCGIWTHRSPY: { struct iw_thrspy threshold; if((event->u.data.pointer) && (event->u.data.length)) { memcpy(&threshold, event->u.data.pointer, sizeof(struct iw_thrspy)); printf("Spy threshold crossed on address:%s\n", iw_saether_ntop(&threshold.addr, buffer)); iw_print_stats(buffer, sizeof(buffer), &threshold.qual, iw_range, has_range); printf(" Link %s\n", buffer); } else printf("Invalid Spy Threshold event\n"); } break; /* ----- driver WPA events ----- */ /* Events generated by the driver, used for WPA operation */ case IWEVMICHAELMICFAILURE: if(event->u.data.length >= sizeof(struct iw_michaelmicfailure)) { struct iw_michaelmicfailure mf; memcpy(&mf, event->u.data.pointer, sizeof(mf)); printf("Michael MIC failure flags:0x%X src_addr:%s tsc:%s\n", mf.flags, iw_saether_ntop(&mf.src_addr, buffer2), iw_hexdump(buffer, sizeof(buffer), mf.tsc, IW_ENCODE_SEQ_MAX_SIZE)); } break; case IWEVASSOCREQIE: printf("Association Request IEs:%s\n", iw_hexdump(buffer, sizeof(buffer), event->u.data.pointer, event->u.data.length)); break; case IWEVASSOCRESPIE: printf("Association Response IEs:%s\n", iw_hexdump(buffer, sizeof(buffer), event->u.data.pointer, event->u.data.length)); break; case IWEVPMKIDCAND: if(event->u.data.length >= sizeof(struct iw_pmkid_cand)) { struct iw_pmkid_cand cand; memcpy(&cand, event->u.data.pointer, sizeof(cand)); printf("PMKID candidate flags:0x%X index:%d bssid:%s\n", cand.flags, cand.index, iw_saether_ntop(&cand.bssid, buffer)); } break; /* ----- junk ----- */ /* other junk not currently in use */ case SIOCGIWRATE: iw_print_bitrate(buffer, sizeof(buffer), event->u.bitrate.value); printf("New Bit Rate:%s\n", buffer); break; case SIOCGIWNAME: printf("Protocol:%-1.16s\n", event->u.name); break; case IWEVQUAL: { event->u.qual.updated = 0x0; /* Not that reliable, disable */ iw_print_stats(buffer, sizeof(buffer), &event->u.qual, iw_range, has_range); printf("Link %s\n", buffer); break; } default: printf("(Unknown Wireless event 0x%04X)\n", event->cmd); } /* switch(event->cmd) */ return(0); }
/* ------------------------------------------------------------------ WirelessInterface_ScanItem */ static int WirelessInterface_ScanItem(wifacesd* data, iwevent* event, iwrange* range, int has_range) { static char buf[128]; memset(data, 0, sizeof(wifacesd)); switch (event->cmd) { case SIOCGIWAP: { iw_ether_ntop((const struct ether_addr*)(event->u.ap_addr.sa_data), buf); data->keys[0] = IWSCAN_KE_BSSID; data->objs[0] = Py_BuildValue("s", buf); data->num = 1; return 1; } case SIOCGIWFREQ: { double freq = iw_freq2float(&(event->u.freq)); int channel; if (freq <= 14.0) channel = iw_channel_to_freq((int)(freq), &freq, range); else channel = iw_freq_to_channel(freq, range); iw_print_freq_value(buf, sizeof(buf), freq); data->keys[0] = IWSCAN_KE_FREQUENCY; data->keys[1] = IWSCAN_KE_CHANNEL; data->objs[0] = Py_BuildValue("s", buf); data->objs[1] = Py_BuildValue("i", channel); data->num = 2; return 0; } case SIOCGIWMODE: { data->keys[0] = IWSCAN_KE_MODE; data->objs[0] = Py_BuildValue("s", iw_operation_mode[event->u.mode]); data->num = 1; return 0; } case SIOCGIWNAME: { data->keys[0] = IWSCAN_KE_PROTOCOL; data->objs[0] = Py_BuildValue("s", event->u.name); data->num = 1; return 0; } case SIOCGIWESSID: { memcpy(buf, event->u.essid.pointer, event->u.essid.length); buf[event->u.essid.length] = 0x0; data->keys[0] = IWSCAN_KE_ESSID; data->objs[0] = Py_BuildValue("s", buf); data->num = 1; return 0; } case SIOCGIWENCODE: { PyObject* pybool; if (event->u.data.flags & IW_ENCODE_DISABLED) pybool = Py_False; else pybool = Py_True; Py_INCREF(pybool); data->keys[0] = IWSCAN_KE_ENC; data->objs[0] = pybool; data->num = 1; return 0; } case SIOCGIWRATE: { iw_print_bitrate(buf, sizeof(buf), event->u.bitrate.value); data->keys[0] = IWSCAN_KE_BITRATE; data->objs[0] = Py_BuildValue("s", buf); data->num = 1; return 0; } case IWEVQUAL: { iw_print_stats(buf, sizeof(buf), &event->u.qual, range, has_range); data->keys[0] = IWSCAN_KE_QUAL; data->keys[1] = IWSCAN_KE_STATS; data->objs[0] = Py_BuildValue("i", event->u.qual.qual); data->objs[1] = Py_BuildValue("s", buf); data->num = 2; return 0; } case IWEVGENIE: { unsigned char* buffer = event->u.data.pointer; int buflen = event->u.data.length; int offset = 0; data->keys[0] = IWSCAN_KE_IE; //PyObject* ie_list = PyList_New(0); //data->objs[0] = ie_list; while (offset <= (buflen - 2)) { //PyList_Append(ie_list, WirelessInterface_ScanIe(buffer + offset, buflen)); data->objs[0] = WirelessInterface_ScanIe(buffer + offset, buflen); offset += buffer[offset + 1] + 2; } data->num = 1; return 0; } default: return 0; } }
/* * Print one element from the scanning results */ static inline int print_event_token(struct iw_event * event, /* Extracted token */ struct iw_range * iwrange, /* Range info */ int has_range) { char buffer[128]; /* Temporary buffer */ /* Now, let's decode the event */ switch(event->cmd) { /* ----- set events ----- */ /* Events that result from a "SET XXX" operation by the user */ case SIOCSIWNWID: if(event->u.nwid.disabled) printf("NWID:off/any\n"); else printf("NWID:%X\n", event->u.nwid.value); break; case SIOCSIWFREQ: { float freq; /* Frequency/channel */ freq = iw_freq2float(&(event->u.freq)); iw_print_freq(buffer, freq); printf("%s\n", buffer); } break; case SIOCSIWMODE: printf("Mode:%s\n", iw_operation_mode[event->u.mode]); break; case SIOCSIWESSID: { char essid[IW_ESSID_MAX_SIZE+1]; if((event->u.essid.pointer) && (event->u.essid.length)) memcpy(essid, event->u.essid.pointer, event->u.essid.length); essid[event->u.essid.length] = '\0'; if(event->u.essid.flags) { /* Does it have an ESSID index ? */ if((event->u.essid.flags & IW_ENCODE_INDEX) > 1) printf("ESSID:\"%s\" [%d]\n", essid, (event->u.essid.flags & IW_ENCODE_INDEX)); else printf("ESSID:\"%s\"\n", essid); } else printf("ESSID:off/any\n"); } break; case SIOCSIWENCODE: { unsigned char key[IW_ENCODING_TOKEN_MAX]; if(event->u.data.pointer) memcpy(key, event->u.essid.pointer, event->u.data.length); else event->u.data.flags |= IW_ENCODE_NOKEY; printf("Encryption key:"); if(event->u.data.flags & IW_ENCODE_DISABLED) printf("off\n"); else { /* Display the key */ iw_print_key(buffer, key, event->u.data.length, event->u.data.flags); printf("%s", buffer); /* Other info... */ if((event->u.data.flags & IW_ENCODE_INDEX) > 1) printf(" [%d]", event->u.data.flags & IW_ENCODE_INDEX); if(event->u.data.flags & IW_ENCODE_RESTRICTED) printf(" Encryption mode:restricted"); if(event->u.data.flags & IW_ENCODE_OPEN) printf(" Encryption mode:open"); printf("\n"); } } break; /* ----- driver events ----- */ /* Events generated by the driver when something important happens */ case SIOCGIWAP: printf("New Access Point/Cell address:%s\n", iw_pr_ether(buffer, event->u.ap_addr.sa_data)); break; case SIOCGIWSCAN: printf("Scan request completed\n"); break; case IWEVTXDROP: printf("Tx packet dropped:%s\n", iw_pr_ether(buffer, event->u.addr.sa_data)); break; #if WIRELESS_EXT > 14 case IWEVCUSTOM: { char custom[IW_CUSTOM_MAX+1]; if((event->u.data.pointer) && (event->u.data.length)) memcpy(custom, event->u.data.pointer, event->u.data.length); custom[event->u.data.length] = '\0'; printf("Custom driver event:%s\n", custom); } break; case IWEVREGISTERED: printf("Registered node:%s\n", iw_pr_ether(buffer, event->u.addr.sa_data)); break; case IWEVEXPIRED: printf("Expired node:%s\n", iw_pr_ether(buffer, event->u.addr.sa_data)); break; #endif /* WIRELESS_EXT > 14 */ /* ----- junk ----- */ /* other junk not currently in use */ case SIOCGIWRATE: iw_print_bitrate(buffer, event->u.bitrate.value); printf("Bit Rate:%s\n", buffer); break; case IWEVQUAL: { event->u.qual.updated = 0x0; /* Not that reliable, disable */ iw_print_stats(buffer, &event->u.qual, iwrange, has_range); printf("Link %s\n", buffer); break; } default: printf("(Unknown Wireless event 0x%04X)\n", event->cmd); } /* switch(event->cmd) */ return(0); }
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down) { const char *walk; char *outwalk = buffer; wireless_info_t info; INSTANCE(interface); const char *ip_address = get_ip_addr(interface); if (ip_address == NULL) { START_COLOR("color_bad"); outwalk += sprintf(outwalk, "%s", format_down); goto out; } if (get_wireless_info(interface, &info)) { walk = format_up; if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) START_COLOR((info.quality < info.quality_average ? "color_degraded" : "color_good")); else START_COLOR("color_good"); } else { walk = format_down; START_COLOR("color_bad"); } for (; *walk != '\0'; walk++) { if (*walk != '%') { *(outwalk++) = *walk; continue; } if (BEGINS_WITH(walk+1, "quality")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) { if (info.quality_max) outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.quality, info.quality_max)); else outwalk += sprintf(outwalk, "%d", info.quality); } else { *(outwalk++) = '?'; } walk += strlen("quality"); } if (BEGINS_WITH(walk+1, "signal")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) { if (info.signal_level_max) outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.signal_level, info.signal_level_max)); else outwalk += sprintf(outwalk, "%d dBm", info.signal_level); } else { *(outwalk++) = '?'; } walk += strlen("signal"); } if (BEGINS_WITH(walk+1, "noise")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) { if (info.noise_level_max) outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.noise_level, info.noise_level_max)); else outwalk += sprintf(outwalk, "%d dBm", info.noise_level); } else { *(outwalk++) = '?'; } walk += strlen("noise"); } if (BEGINS_WITH(walk+1, "essid")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_ESSID) outwalk += sprintf(outwalk, "%s", info.essid); else *(outwalk++) = '?'; walk += strlen("essid"); } if (BEGINS_WITH(walk+1, "ip")) { outwalk += sprintf(outwalk, "%s", ip_address); walk += strlen("ip"); } #ifdef LINUX if (BEGINS_WITH(walk+1, "bitrate")) { char br_buffer[128]; iw_print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate); outwalk += sprintf(outwalk, "%s", br_buffer); walk += strlen("bitrate"); } #endif } out: END_COLOR; OUTPUT_FULL_TEXT(buffer); }
/* * Print one element from the scanning results */ static inline void print_scanning_token(struct stream_descr * stream, /* Stream of events */ struct iw_event * event, /* Extracted token */ struct iwscan_state * state, struct iw_range * iw_range, /* Range info */ int has_range) { char buffer[128]; /* Temporary buffer */ /* Now, let's decode the event */ switch(event->cmd) { case SIOCGIWAP: printf(" Cell %02d - Address: %s\n", state->ap_num, iw_saether_ntop(&event->u.ap_addr, buffer)); state->ap_num++; break; case SIOCGIWNWID: if(event->u.nwid.disabled) printf(" NWID:off/any\n"); else printf(" NWID:%X\n", event->u.nwid.value); break; case SIOCGIWFREQ: { double freq; /* Frequency/channel */ int channel = -1; /* Converted to channel */ freq = iw_freq2float(&(event->u.freq)); /* Convert to channel if possible */ if(has_range) channel = iw_freq_to_channel(freq, iw_range); iw_print_freq(buffer, sizeof(buffer), freq, channel, event->u.freq.flags); printf(" %s\n", buffer); } break; case SIOCGIWMODE: printf(" Mode:%s\n", iw_operation_mode[event->u.mode]); break; case SIOCGIWNAME: printf(" Protocol:%-1.16s\n", event->u.name); break; case SIOCGIWESSID: { char essid[IW_ESSID_MAX_SIZE+1]; memset(essid, '\0', sizeof(essid)); if((event->u.essid.pointer) && (event->u.essid.length)) memcpy(essid, event->u.essid.pointer, event->u.essid.length); if(event->u.essid.flags) { /* Does it have an ESSID index ? */ if((event->u.essid.flags & IW_ENCODE_INDEX) > 1) printf(" ESSID:\"%s\" [%d]\n", essid, (event->u.essid.flags & IW_ENCODE_INDEX)); else printf(" ESSID:\"%s\"\n", essid); } else printf(" ESSID:off/any/hidden\n"); } break; case SIOCGIWENCODE: { unsigned char key[IW_ENCODING_TOKEN_MAX]; if(event->u.data.pointer) memcpy(key, event->u.data.pointer, event->u.data.length); else event->u.data.flags |= IW_ENCODE_NOKEY; printf(" Encryption key:"); if(event->u.data.flags & IW_ENCODE_DISABLED) printf("off\n"); else { /* Display the key */ iw_print_key(buffer, sizeof(buffer), key, event->u.data.length, event->u.data.flags); printf("%s", buffer); /* Other info... */ if((event->u.data.flags & IW_ENCODE_INDEX) > 1) printf(" [%d]", event->u.data.flags & IW_ENCODE_INDEX); if(event->u.data.flags & IW_ENCODE_RESTRICTED) printf(" Security mode:restricted"); if(event->u.data.flags & IW_ENCODE_OPEN) printf(" Security mode:open"); printf("\n"); } } break; case SIOCGIWRATE: if(state->val_index == 0) printf(" Bit Rates:"); else if((state->val_index % 5) == 0) printf("\n "); else printf("; "); iw_print_bitrate(buffer, sizeof(buffer), event->u.bitrate.value); printf("%s", buffer); /* Check for termination */ if(stream->value == NULL) { printf("\n"); state->val_index = 0; } else state->val_index++; break; case IWEVQUAL: { iw_print_stats(buffer, sizeof(buffer), &event->u.qual, iw_range, has_range); printf(" %s\n", buffer); break; } case IWEVGENIE: /* Informations Elements are complex, let's do only some of them */ iw_print_gen_ie(event->u.data.pointer, event->u.data.length); break; case IWEVCUSTOM: { char custom[IW_CUSTOM_MAX+1]; if((event->u.data.pointer) && (event->u.data.length)) memcpy(custom, event->u.data.pointer, event->u.data.length); custom[event->u.data.length] = '\0'; printf(" Extra:%s\n", custom); } break; default: printf(" (Unknown Wireless Token 0x%04X)\n", event->cmd); } /* switch(event->cmd) */ }