📄 at76c503.c
字号:
return ret;}static int dump_mib_mac_addr(struct at76c503 *dev) __attribute__ ((unused));static int dump_mib_mac_addr(struct at76c503 *dev){ int ret = 0; struct mib_mac_addr *mac_addr = kmalloc(sizeof(struct mib_mac_addr), GFP_KERNEL); if(!mac_addr){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_MAC_ADD, (u8*)mac_addr, sizeof(struct mib_mac_addr)); if(ret < 0){ err("%s: get_mib (MAC_ADDR) failed: %d", dev->netdev->name, ret); goto err; } dbg_uc("%s: MIB MAC_ADDR: mac_addr %s res 0x%x 0x%x group_addr %s status %d %d %d %d", dev->netdev->name, mac2str(mac_addr->mac_addr), mac_addr->res[0], mac_addr->res[1], hex2str(dev->obuf, (u8 *)mac_addr->group_addr, min((int)(sizeof(dev->obuf)-1)/2, 4*ETH_ALEN), '\0'), mac_addr->group_addr_status[0], mac_addr->group_addr_status[1], mac_addr->group_addr_status[2], mac_addr->group_addr_status[3]); err: kfree(mac_addr); exit: return ret;}static int dump_mib_mac_wep(struct at76c503 *dev) __attribute__ ((unused));static int dump_mib_mac_wep(struct at76c503 *dev){ int ret = 0; struct mib_mac_wep *mac_wep = kmalloc(sizeof(struct mib_mac_wep), GFP_KERNEL); if(!mac_wep){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_MAC_WEP, (u8*)mac_wep, sizeof(struct mib_mac_wep)); if(ret < 0){ err("%s: get_mib (MAC_WEP) failed: %d", dev->netdev->name, ret); goto err; } dbg_uc("%s: MIB MAC_WEP: priv_invoked %u def_key_id %u key_len %u " "excl_unencr %u wep_icv_err %u wep_excluded %u encr_level %u key %d: %s", dev->netdev->name, mac_wep->privacy_invoked, mac_wep->wep_default_key_id, mac_wep->wep_key_mapping_len, mac_wep->exclude_unencrypted,le32_to_cpu( mac_wep->wep_icv_error_count), le32_to_cpu(mac_wep->wep_excluded_count), mac_wep->encryption_level, mac_wep->wep_default_key_id, mac_wep->wep_default_key_id < 4 ? hex2str(dev->obuf, mac_wep->wep_default_keyvalue[mac_wep->wep_default_key_id], min((int)(sizeof(dev->obuf)-1)/2, mac_wep->encryption_level == 2 ? 13 : 5), '\0') : "<invalid key id>"); err: kfree(mac_wep); exit: return ret;}static int dump_mib_mac_mgmt(struct at76c503 *dev) __attribute__ ((unused));static int dump_mib_mac_mgmt(struct at76c503 *dev){ int ret = 0; struct mib_mac_mgmt *mac_mgmt = kmalloc(sizeof(struct mib_mac_mgmt), GFP_KERNEL); char country_string[4]; if(!mac_mgmt){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_MAC_MGMT, (u8*)mac_mgmt, sizeof(struct mib_mac_mgmt)); if(ret < 0){ err("%s: get_mib failed: %d", dev->netdev->name, ret); goto err; } memcpy(&country_string, mac_mgmt->country_string, 3); country_string[3] = '\0'; dbg_uc("%s: MIB MAC_MGMT: beacon_period %d CFP_max_duration %d " "medium_occupancy_limit %d station_id 0x%x ATIM_window %d " "CFP_mode %d privacy_opt_impl %d DTIM_period %d CFP_period %d " "current_bssid %s current_essid %s current_bss_type %d " "pm_mode %d ibss_change %d res %d " "multi_domain_capability_implemented %d " "international_roaming %d country_string %s", dev->netdev->name, le16_to_cpu(mac_mgmt->beacon_period), le16_to_cpu(mac_mgmt->CFP_max_duration), le16_to_cpu(mac_mgmt->medium_occupancy_limit), le16_to_cpu(mac_mgmt->station_id), le16_to_cpu(mac_mgmt->ATIM_window), mac_mgmt->CFP_mode, mac_mgmt->privacy_option_implemented, mac_mgmt->DTIM_period, mac_mgmt->CFP_period, mac2str(mac_mgmt->current_bssid), hex2str(dev->obuf, (u8 *)mac_mgmt->current_essid, min((int)(sizeof(dev->obuf)-1)/2, IW_ESSID_MAX_SIZE), '\0'), mac_mgmt->current_bss_type, mac_mgmt->power_mgmt_mode, mac_mgmt->ibss_change, mac_mgmt->res, mac_mgmt->multi_domain_capability_implemented, mac_mgmt->multi_domain_capability_enabled, country_string); err: kfree(mac_mgmt); exit: return ret;}static int dump_mib_mac(struct at76c503 *dev) __attribute__ ((unused));static int dump_mib_mac(struct at76c503 *dev){ int ret = 0; struct mib_mac *mac = kmalloc(sizeof(struct mib_mac), GFP_KERNEL); if(!mac){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_MAC, (u8*)mac, sizeof(struct mib_mac)); if(ret < 0){ err("%s: get_mib failed: %d", dev->netdev->name, ret); goto err; } dbg_uc("%s: MIB MAC: max_tx_msdu_lifetime %d max_rx_lifetime %d " "frag_threshold %d rts_threshold %d cwmin %d cwmax %d " "short_retry_time %d long_retry_time %d scan_type %d " "scan_channel %d probe_delay %u min_channel_time %d " "max_channel_time %d listen_int %d desired_ssid %s " "desired_bssid %s desired_bsstype %d", dev->netdev->name, le32_to_cpu(mac->max_tx_msdu_lifetime), le32_to_cpu(mac->max_rx_lifetime), le16_to_cpu(mac->frag_threshold), le16_to_cpu(mac->rts_threshold), le16_to_cpu(mac->cwmin), le16_to_cpu(mac->cwmax), mac->short_retry_time, mac->long_retry_time, mac->scan_type, mac->scan_channel, le16_to_cpu(mac->probe_delay), le16_to_cpu(mac->min_channel_time), le16_to_cpu(mac->max_channel_time), le16_to_cpu(mac->listen_interval), hex2str(dev->obuf, mac->desired_ssid, min((int)(sizeof(dev->obuf)-1)/2, IW_ESSID_MAX_SIZE), '\0'), mac2str(mac->desired_bssid), mac->desired_bsstype); err: kfree(mac); exit: return ret;}static int dump_mib_phy(struct at76c503 *dev) __attribute__ ((unused));static int dump_mib_phy(struct at76c503 *dev){ int ret = 0; struct mib_phy *phy = kmalloc(sizeof(struct mib_phy), GFP_KERNEL); if(!phy){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_PHY, (u8*)phy, sizeof(struct mib_phy)); if(ret < 0){ err("%s: get_mib failed: %d", dev->netdev->name, ret); goto err; } dbg_uc("%s: MIB PHY: ed_threshold %d slot_time %d sifs_time %d " "preamble_length %d plcp_header_length %d mpdu_max_length %d " "cca_mode_supported %d operation_rate_set " "0x%x 0x%x 0x%x 0x%x channel_id %d current_cca_mode %d " "phy_type %d current_reg_domain %d", dev->netdev->name, le32_to_cpu(phy->ed_threshold), le16_to_cpu(phy->slot_time), le16_to_cpu(phy->sifs_time), le16_to_cpu(phy->preamble_length), le16_to_cpu(phy->plcp_header_length), le16_to_cpu(phy->mpdu_max_length), le16_to_cpu(phy->cca_mode_supported), phy->operation_rate_set[0], phy->operation_rate_set[1], phy->operation_rate_set[2], phy->operation_rate_set[3], phy->channel_id, phy->current_cca_mode, phy->phy_type, phy->current_reg_domain); err: kfree(phy); exit: return ret;}static int dump_mib_local(struct at76c503 *dev) __attribute__ ((unused));static int dump_mib_local(struct at76c503 *dev){ int ret = 0; struct mib_local *local = kmalloc(sizeof(struct mib_phy), GFP_KERNEL); if(!local){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_LOCAL, (u8*)local, sizeof(struct mib_local)); if(ret < 0){ err("%s: get_mib failed: %d", dev->netdev->name, ret); goto err; } dbg_uc("%s: MIB PHY: beacon_enable %d txautorate_fallback %d " "ssid_size %d promiscuous_mode %d preamble_type %d", dev->netdev->name, local->beacon_enable, local->txautorate_fallback, local->ssid_size, local->promiscuous_mode, local->preamble_type); err: kfree(local); exit: return ret;}static int get_mib_mdomain(struct at76c503 *dev, struct mib_mdomain *val) __attribute__ ((unused));static int get_mib_mdomain(struct at76c503 *dev, struct mib_mdomain *val){ int ret = 0; struct mib_mdomain *mdomain = kmalloc(sizeof(struct mib_mdomain), GFP_KERNEL); if(!mdomain){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_MDOMAIN, (u8*)mdomain, sizeof(struct mib_mdomain)); if(ret < 0){ err("%s: get_mib failed: %d", dev->netdev->name, ret); goto err; } memcpy(val, mdomain, sizeof(*val)); err: kfree(mdomain); exit: return ret;}static void dump_mib_mdomain(struct at76c503 *dev) __attribute__ ((unused));static void dump_mib_mdomain(struct at76c503 *dev){ char obuf1[2*14+1], obuf2[2*14+1]; /* to hexdump tx_powerlevel, channel_list */ int ret; struct mib_mdomain mdomain; if ((ret=get_mib_mdomain(dev, &mdomain)) < 0) { err("%s: get_mib_mdomain returned %d", __FUNCTION__, ret); return; } dbg(DBG_MIB, "%s: MIB MDOMAIN: channel_list %s tx_powerlevel %s", dev->netdev->name, hex2str(obuf1, mdomain.channel_list, (sizeof(obuf1)-1)/2,'\0'), hex2str(obuf2, mdomain.tx_powerlevel, (sizeof(obuf2)-1)/2,'\0'));}staticint get_current_bssid(struct at76c503 *dev){ int ret = 0; struct mib_mac_mgmt *mac_mgmt = kmalloc(sizeof(struct mib_mac_mgmt), GFP_KERNEL); if(!mac_mgmt){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_MAC_MGMT, (u8*)mac_mgmt, sizeof(struct mib_mac_mgmt)); if(ret < 0){ err("%s: get_mib failed: %d", dev->netdev->name, ret); goto err; } memcpy(dev->bssid, mac_mgmt->current_bssid, ETH_ALEN); info("using BSSID %s", mac2str(dev->bssid)); err: kfree(mac_mgmt); exit: return ret;}staticint get_current_channel(struct at76c503 *dev){ int ret = 0; struct mib_phy *phy = kmalloc(sizeof(struct mib_phy), GFP_KERNEL); if(!phy){ ret = -ENOMEM; goto exit; } ret = get_mib(dev->udev, MIB_PHY, (u8*)phy, sizeof(struct mib_phy)); if(ret < 0){ err("%s: get_mib(MIB_PHY) failed: %d", dev->netdev->name, ret); goto err; } dev->channel = phy->channel_id; err: kfree(phy); exit: return ret;}/* == PROC start_scan == start a scan. use_essid is != 0 if any probe_delay (if scan mode is not passive) should contain the ESSID configured. ir_step describes the international roaming step (0, 1) */staticint start_scan(struct at76c503 *dev, int use_essid, int ir_step){ struct at76c503_start_scan scan; memset(&scan, 0, sizeof(struct at76c503_start_scan)); memset(scan.bssid, 0xff, ETH_ALEN); if (use_essid) { memcpy(scan.essid, dev->essid, IW_ESSID_MAX_SIZE); scan.essid_size = dev->essid_size; } else scan.essid_size = 0; //jal: why should we start at a certain channel? we do scan the whole range //allowed by reg domain. scan.channel = dev->channel; /* atmelwlandriver differs between scan type 0 and 1 (active/passive) For ad-hoc mode, it uses type 0 only.*/ if ((dev->international_roaming == IR_ON && ir_step == 0) || dev->iw_mode == IW_MODE_MONITOR) scan.scan_type = SCAN_TYPE_PASSIVE; else scan.scan_type = dev->scan_mode; /* INFO: For probe_delay, not multiplying by 1024 as this will be slightly less than min_channel_time (per spec: probe delay < min. channel time) */ if (dev->istate == MONITORING) { scan.min_channel_time = cpu_to_le16(dev->monitor_scan_min_time); scan.max_channel_time = cpu_to_le16(dev->monitor_scan_max_time); scan.probe_delay = cpu_to_le16(dev->monitor_scan_min_time * 1000); } else { scan.min_channel_time = cpu_to_le16(dev->scan_min_time); scan.max_channel_time = cpu_to_le16(dev->scan_max_time); scan.probe_delay = cpu_to_le16(dev->scan_min_time * 1000); } if (dev->international_roaming == IR_ON && ir_step == 1) scan.international_scan = 0; else scan.international_scan = dev->international_roaming; /* other values are set to 0 for type 0 */ dbg(DBG_PROGRESS, "%s: start_scan (use_essid = %d, intl = %d, " "channel = %d, probe_delay = %d, scan_min_time = %d, " "scan_max_time = %d)", dev->netdev->name, use_essid, scan.international_scan, scan.channel, le16_to_cpu(scan.probe_delay), le16_to_cpu(scan.min_channel_time), le16_to_cpu(scan.max_channel_time)); return set_card_command(dev->udev, CMD_SCAN, (unsigned char*)&scan, sizeof(scan));}staticint start_ibss(struct at76c503 *dev){ struct at76c503_start_bss bss; memset(&bss, 0, sizeof(struct at76c503_start_bss)); memset(bss.bssid, 0xff, ETH_ALEN); memcpy(bss.essid, dev->essid, IW_ESSID_MAX_SIZE); bss.essid_size = dev->essid_size; bss.bss_type = ADHOC_MODE; bss.channel = dev->channel; return set_card_command(dev->udev, CMD_START_IBSS, (unsigned char*)&bss, sizeof(struct at76c503_start_bss));}/* idx points into dev->bss */staticint join_bss(struct at76c503 *dev, struct bss_info *ptr){ struct at76c503_join join;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -