📄 iwlist.c
字号:
pwrq->u.power.flags = flags; if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, pwrq) >= 0) { /* Let's check the value and its type */ if(pwrq->u.power.flags & IW_POWER_TYPE) { iw_print_pm_value(buffer, buflen, pwrq->u.power.value, pwrq->u.power.flags, we_version_compiled); printf("\n %s", buffer); } } return(pwrq->u.power.flags);}/*------------------------------------------------------------------*//* * Print Power Management range for each type */static voidprint_pm_value_range(char * name, int mask, int iwr_flags, int iwr_min, int iwr_max, char * buffer, int buflen, int we_version_compiled){ if(iwr_flags & mask) { int flags = (iwr_flags & ~(IW_POWER_MIN | IW_POWER_MAX)); /* Display if auto or fixed */ printf("%s %s ; ", (iwr_flags & IW_POWER_MIN) ? "Auto " : "Fixed", name); /* Print the range */ iw_print_pm_value(buffer, buflen, iwr_min, flags | IW_POWER_MIN, we_version_compiled); printf("%s\n ", buffer); iw_print_pm_value(buffer, buflen, iwr_max, flags | IW_POWER_MAX, we_version_compiled); printf("%s\n ", buffer); }}/*------------------------------------------------------------------*//* * Power Management types of values */static const unsigned int pm_type_flags[] = { IW_POWER_PERIOD, IW_POWER_TIMEOUT, IW_POWER_SAVING,};static const int pm_type_flags_size = (sizeof(pm_type_flags)/sizeof(pm_type_flags[0]));/*------------------------------------------------------------------*//* * Print Power Management info for each device */static intprint_pm_info(int skfd, char * ifname, char * args[], /* Command line args */ int count) /* Args count */{ struct iwreq wrq; struct iw_range range; char buffer[128]; /* Avoid "Unused parameter" warning */ args = args; count = count; /* Extract range info */ if((iw_get_range_info(skfd, ifname, &range) < 0) || (range.we_version_compiled < 10)) fprintf(stderr, "%-8.16s no power management information.\n\n", ifname); else { printf("%-8.16s ", ifname); /* Display modes availables */ if(range.pm_capa & IW_POWER_MODE) { printf("Supported modes :\n "); if(range.pm_capa & (IW_POWER_UNICAST_R | IW_POWER_MULTICAST_R)) printf("\t\to Receive all packets (unicast & multicast)\n "); if(range.pm_capa & IW_POWER_UNICAST_R) printf("\t\to Receive Unicast only (discard multicast)\n "); if(range.pm_capa & IW_POWER_MULTICAST_R) printf("\t\to Receive Multicast only (discard unicast)\n "); if(range.pm_capa & IW_POWER_FORCE_S) printf("\t\to Force sending using Power Management\n "); if(range.pm_capa & IW_POWER_REPEATER) printf("\t\to Repeat multicast\n "); } /* Display min/max period availables */ print_pm_value_range("period ", IW_POWER_PERIOD, range.pmp_flags, range.min_pmp, range.max_pmp, buffer, sizeof(buffer), range.we_version_compiled); /* Display min/max timeout availables */ print_pm_value_range("timeout", IW_POWER_TIMEOUT, range.pmt_flags, range.min_pmt, range.max_pmt, buffer, sizeof(buffer), range.we_version_compiled); /* Display min/max saving availables */ print_pm_value_range("saving ", IW_POWER_SAVING, range.pms_flags, range.min_pms, range.max_pms, buffer, sizeof(buffer), range.we_version_compiled); /* Get current Power Management settings */ wrq.u.power.flags = 0; if(iw_get_ext(skfd, ifname, SIOCGIWPOWER, &wrq) >= 0) { int flags = wrq.u.power.flags; /* Is it disabled ? */ if(wrq.u.power.disabled) printf("Current mode:off\n"); else { unsigned int pm_type = 0; unsigned int pm_mask = 0; unsigned int remain_mask = range.pm_capa & IW_POWER_TYPE; int i = 0; /* Let's check the mode */ iw_print_pm_mode(buffer, sizeof(buffer), flags); printf("Current %s", buffer); /* Let's check if nothing (simply on) */ if((flags & IW_POWER_MODE) == IW_POWER_ON) printf("mode:on"); /* Let's check the value and its type */ if(wrq.u.power.flags & IW_POWER_TYPE) { iw_print_pm_value(buffer, sizeof(buffer), wrq.u.power.value, wrq.u.power.flags, range.we_version_compiled); printf("\n %s", buffer); } while(1) { /* Deal with min/max for the current value */ pm_mask = 0; /* If we have been returned a MIN value, ask for the MAX */ if(flags & IW_POWER_MIN) pm_mask = IW_POWER_MAX; /* If we have been returned a MAX value, ask for the MIN */ if(flags & IW_POWER_MAX) pm_mask = IW_POWER_MIN; /* If we have something to ask for... */ if(pm_mask) { pm_mask |= pm_type; get_pm_value(skfd, ifname, &wrq, pm_mask, buffer, sizeof(buffer), range.we_version_compiled); } /* Remove current type from mask */ remain_mask &= ~(wrq.u.power.flags); /* Check what other types we still have to read */ while(i < pm_type_flags_size) { pm_type = remain_mask & pm_type_flags[i]; if(pm_type) break; i++; } /* Nothing anymore : exit the loop */ if(!pm_type) break; /* Ask for this other type of value */ flags = get_pm_value(skfd, ifname, &wrq, pm_type, buffer, sizeof(buffer), range.we_version_compiled); /* Loop back for min/max */ } printf("\n"); } } printf("\n"); } return(0);}#ifndef WE_ESSENTIAL/************************** TRANSMIT POWER **************************//*------------------------------------------------------------------*//* * Print the number of available transmit powers for the device */static intprint_txpower_info(int skfd, char * ifname, char * args[], /* Command line args */ int count) /* Args count */{ struct iwreq wrq; struct iw_range range; int dbm; int mwatt; int k; /* Avoid "Unused parameter" warning */ args = args; count = count; /* Extract range info */ if((iw_get_range_info(skfd, ifname, &range) < 0) || (range.we_version_compiled < 10)) fprintf(stderr, "%-8.16s no transmit-power information.\n\n", ifname); else { if((range.num_txpower <= 0) || (range.num_txpower > IW_MAX_TXPOWER)) printf("%-8.16s unknown transmit-power information.\n\n", ifname); else { printf("%-8.16s %d available transmit-powers :\n", ifname, range.num_txpower); /* Print them all */ for(k = 0; k < range.num_txpower; k++) { /* Check for relative values */ if(range.txpower_capa & IW_TXPOW_RELATIVE) { printf("\t %d (no units)\n", range.txpower[k]); } else { if(range.txpower_capa & IW_TXPOW_MWATT) { dbm = iw_mwatt2dbm(range.txpower[k]); mwatt = range.txpower[k]; } else { dbm = range.txpower[k]; mwatt = iw_dbm2mwatt(range.txpower[k]); } printf("\t %d dBm \t(%d mW)\n", dbm, mwatt); } } } /* Get current Transmit Power */ if(iw_get_ext(skfd, ifname, SIOCGIWTXPOW, &wrq) >= 0) { printf(" Current Tx-Power"); /* Disabled ? */ if(wrq.u.txpower.disabled) printf(":off\n\n"); else { /* Fixed ? */ if(wrq.u.txpower.fixed) printf("="); else printf(":"); /* Check for relative values */ if(wrq.u.txpower.flags & IW_TXPOW_RELATIVE) { /* I just hate relative value, because they are * driver specific, so not very meaningfull to apps. * But, we have to support that, because * this is the way hardware is... */ printf("\t %d (no units)\n", wrq.u.txpower.value); } else { if(wrq.u.txpower.flags & IW_TXPOW_MWATT) { dbm = iw_mwatt2dbm(wrq.u.txpower.value); mwatt = wrq.u.txpower.value; } else { dbm = wrq.u.txpower.value; mwatt = iw_dbm2mwatt(wrq.u.txpower.value); } printf("%d dBm \t(%d mW)\n\n", dbm, mwatt); } } } } return(0);}/*********************** RETRY LIMIT/LIFETIME ***********************//*------------------------------------------------------------------*//* * Print one retry value */static intget_retry_value(int skfd, char * ifname, struct iwreq * pwrq, int flags, char * buffer, int buflen, int we_version_compiled){ /* Get Another retry value */ pwrq->u.retry.flags = flags; if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, pwrq) >= 0) { /* Let's check the value and its type */ if(pwrq->u.retry.flags & IW_RETRY_TYPE) { iw_print_retry_value(buffer, buflen, pwrq->u.retry.value, pwrq->u.retry.flags, we_version_compiled); printf("%s\n ", buffer); } } return(pwrq->u.retry.flags);}/*------------------------------------------------------------------*//* * Print Power Management range for each type */static voidprint_retry_value_range(char * name, int mask, int iwr_flags, int iwr_min, int iwr_max, char * buffer, int buflen, int we_version_compiled){ if(iwr_flags & mask) { int flags = (iwr_flags & ~(IW_RETRY_MIN | IW_RETRY_MAX)); /* Display if auto or fixed */ printf("%s %s ; ", (iwr_flags & IW_POWER_MIN) ? "Auto " : "Fixed", name); /* Print the range */ iw_print_retry_value(buffer, buflen, iwr_min, flags | IW_POWER_MIN, we_version_compiled); printf("%s\n ", buffer); iw_print_retry_value(buffer, buflen, iwr_max, flags | IW_POWER_MAX, we_version_compiled); printf("%s\n ", buffer); }}/*------------------------------------------------------------------*//* * Print Retry info for each device */static intprint_retry_info(int skfd, char * ifname, char * args[], /* Command line args */ int count) /* Args count */{ struct iwreq wrq; struct iw_range range; char buffer[128]; /* Avoid "Unused parameter" warning */ args = args; count = count; /* Extract range info */ if((iw_get_range_info(skfd, ifname, &range) < 0) || (range.we_version_compiled < 11)) fprintf(stderr, "%-8.16s no retry limit/lifetime information.\n\n", ifname); else { printf("%-8.16s ", ifname); /* Display min/max limit availables */ print_retry_value_range("limit ", IW_RETRY_LIMIT, range.retry_flags, range.min_retry, range.max_retry, buffer, sizeof(buffer), range.we_version_compiled); /* Display min/max lifetime availables */ print_retry_value_range("lifetime", IW_RETRY_LIFETIME, range.r_time_flags, range.min_r_time, range.max_r_time, buffer, sizeof(buffer), range.we_version_compiled); /* Get current retry settings */ wrq.u.retry.flags = 0; if(iw_get_ext(skfd, ifname, SIOCGIWRETRY, &wrq) >= 0) { int flags = wrq.u.retry.flags; /* Is it disabled ? */ if(wrq.u.retry.disabled) printf("Current mode:off\n "); else { unsigned int retry_type = 0; unsigned int retry_mask = 0; unsigned int remain_mask = range.retry_capa & IW_RETRY_TYPE; /* Let's check the mode */ printf("Current mode:on\n "); /* Let's check the value and its type */ if(wrq.u.retry.flags & IW_RETRY_TYPE) { iw_print_retry_value(buffer, sizeof(buffer), wrq.u.retry.value, wrq.u.retry.flags, range.we_version_compiled); printf("%s\n ", buffer); } while(1) { /* Deal with min/max/short/long for the current value */ retry_mask = 0; /* If we have been returned a MIN value, ask for the MAX */ if(flags & IW_RETRY_MIN) retry_mask = IW_RETRY_MAX; /* If we have been returned a MAX value, ask for the MIN */ if(flags & IW_RETRY_MAX) retry_mask = IW_RETRY_MIN; /* Same for SHORT and LONG */ if(flags & IW_RETRY_SHORT) retry_mask = IW_RETRY_LONG; if(flags & IW_RETRY_LONG) retry_mask = IW_RETRY_SHORT; /* If we have something to ask for... */ if(retry_mask) { retry_mask |= retry_type; get_retry_value(skfd, ifname, &wrq, retry_mask, buffer, sizeof(buffer), range.we_version_compiled); } /* And if we have both a limit and a lifetime, * ask the other one */ remain_mask &= ~(wrq.u.retry.flags); retry_type = remain_mask; /* Nothing anymore : exit the loop */ if(!retry_type) break; /* Ask for this other type of value */ flags = get_retry_value(skfd, ifname, &wrq, retry_type, buffer, sizeof(buffer), range.we_version_compiled); /* Loop back for min/max/short/long */ } } } printf("\n"); } return(0);}/************************ ACCESS POINT LIST ************************//* * Note : now that we have scanning support, this is depracted and * won't survive long. Actually, next version it's out ! *//*------------------------------------------------------------------*//* * Display the list of ap addresses and the associated stats * Exacly the same as the spy list, only with different IOCTL and messages */static intprint_ap_info(int skfd, char * ifname, char * args[], /* Command line args */ int count) /* Args count */{ struct iwreq wrq; char buffer[(sizeof(struct iw_quality) + sizeof(struct sockaddr)) * IW_MAX_AP]; char temp[128]; struct sockaddr * hwa; struct iw_quality * qual; iwrange range; int has_range = 0; int has_qual = 0; int n; int i; /* Avoid "Unused parameter" warning */ args = args; count = count; /* Collect stats */ wrq.u.data.pointer = (caddr_t) buffer; wrq.u.data.length = IW_MAX_AP; wrq.u.data.flags = 0; if(iw_get_ext(skfd, ifname, SIOCGIWAPLIST, &wrq) < 0) { fprintf(stderr, "%-8.16s Interface doesn't have a list of Peers/Access-Points\n\n", ifname); return(-1); } /* Number of addresses */ n = wrq.u.data.length; has_qual = wrq.u.data.flags; /* The two lists */ hwa = (struct sockaddr *) buffer; qual = (struct iw_quality *) (buffer + (sizeof(struct sockaddr) * n)); /* Check if we have valid mac address type */ if(iw_check_mac_addr_type(skfd, ifname) < 0) { fprintf(stderr, "%-8.16s Interface doesn't support MAC addresses\n\n", ifname); return(-2); } /* Get range info if we can */ if(iw_get_range_info(skfd, ifname, &(range)) >= 0) has_range = 1; /* Display it */ if(n == 0) printf("%-8.16s No Peers/Access-Point in range\n", ifname); else printf("%-8.16s Peers/Access-Points in range:\n", ifname); for(i = 0; i < n; i++) { if(has_qual) { /* Print stats for this address */ printf(" %s : ", iw_saether_ntop(&hwa[i], temp)); iw_print_stats(temp, sizeof(buffer), &qual[i], &range, has_range); printf("%s\n", temp); } else /* Only print the address */ printf(" %s\n", iw_saether_ntop(&hwa[i], temp)); } printf("\n"); return(0);}/******************** WIRELESS EVENT CAPABILITY ********************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -