📄 config.c
字号:
if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL) return -1; if (val[0] == '"') { if (len < 2 || val[len - 1] != '"') return -1; len -= 2; wep->key[keyidx] = os_malloc(len); if (wep->key[keyidx] == NULL) return -1; os_memcpy(wep->key[keyidx], val + 1, len); wep->len[keyidx] = len; } else { if (len & 1) return -1; len /= 2; wep->key[keyidx] = os_malloc(len); if (wep->key[keyidx] == NULL) return -1; wep->len[keyidx] = len; if (hexstr2bin(val, wep->key[keyidx], len) < 0) return -1; } wep->keys_set++; return 0;}static int hostapd_parse_rates(int **rate_list, char *val){ int *list; int count; char *pos, *end; os_free(*rate_list); *rate_list = NULL; pos = val; count = 0; while (*pos != '\0') { if (*pos == ' ') count++; pos++; } list = os_malloc(sizeof(int) * (count + 2)); if (list == NULL) return -1; pos = val; count = 0; while (*pos != '\0') { end = os_strchr(pos, ' '); if (end) *end = '\0'; list[count++] = atoi(pos); if (!end) break; pos = end + 1; } list[count] = -1; *rate_list = list; return 0;}static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname){ struct hostapd_bss_config *bss; if (*ifname == '\0') return -1; bss = os_realloc(conf->bss, (conf->num_bss + 1) * sizeof(struct hostapd_bss_config)); if (bss == NULL) { wpa_printf(MSG_ERROR, "Failed to allocate memory for " "multi-BSS entry"); return -1; } conf->bss = bss; bss = &(conf->bss[conf->num_bss]); os_memset(bss, 0, sizeof(*bss)); bss->radius = os_zalloc(sizeof(*bss->radius)); if (bss->radius == NULL) { wpa_printf(MSG_ERROR, "Failed to allocate memory for " "multi-BSS RADIUS data"); return -1; } conf->num_bss++; conf->last_bss = bss; hostapd_config_defaults_bss(bss); os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1); return 0;}static int valid_cw(int cw){ return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 || cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);}enum { IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */ IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */ IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */ IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */ IEEE80211_TX_QUEUE_DATA4 = 4, IEEE80211_TX_QUEUE_AFTER_BEACON = 6, IEEE80211_TX_QUEUE_BEACON = 7};static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name, char *val){ int num; char *pos; struct hostapd_tx_queue_params *queue; /* skip 'tx_queue_' prefix */ pos = name + 9; if (os_strncmp(pos, "data", 4) == 0 && pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') { num = pos[4] - '0'; pos += 6; } else if (os_strncmp(pos, "after_beacon_", 13) == 0) { num = IEEE80211_TX_QUEUE_AFTER_BEACON; pos += 13; } else if (os_strncmp(pos, "beacon_", 7) == 0) { num = IEEE80211_TX_QUEUE_BEACON; pos += 7; } else { wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos); return -1; } queue = &conf->tx_queue[num]; if (os_strcmp(pos, "aifs") == 0) { queue->aifs = atoi(val); if (queue->aifs < 0 || queue->aifs > 255) { wpa_printf(MSG_ERROR, "Invalid AIFS value %d", queue->aifs); return -1; } } else if (os_strcmp(pos, "cwmin") == 0) { queue->cwmin = atoi(val); if (!valid_cw(queue->cwmin)) { wpa_printf(MSG_ERROR, "Invalid cwMin value %d", queue->cwmin); return -1; } } else if (os_strcmp(pos, "cwmax") == 0) { queue->cwmax = atoi(val); if (!valid_cw(queue->cwmax)) { wpa_printf(MSG_ERROR, "Invalid cwMax value %d", queue->cwmax); return -1; } } else if (os_strcmp(pos, "burst") == 0) { queue->burst = hostapd_config_read_int10(val); } else { wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos); return -1; } queue->configured = 1; return 0;}static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name, char *val){ int num, v; char *pos; struct hostapd_wme_ac_params *ac; /* skip 'wme_ac_' prefix */ pos = name + 7; if (os_strncmp(pos, "be_", 3) == 0) { num = 0; pos += 3; } else if (os_strncmp(pos, "bk_", 3) == 0) { num = 1; pos += 3; } else if (os_strncmp(pos, "vi_", 3) == 0) { num = 2; pos += 3; } else if (os_strncmp(pos, "vo_", 3) == 0) { num = 3; pos += 3; } else { wpa_printf(MSG_ERROR, "Unknown wme name '%s'", pos); return -1; } ac = &conf->wme_ac_params[num]; if (os_strcmp(pos, "aifs") == 0) { v = atoi(val); if (v < 1 || v > 255) { wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v); return -1; } ac->aifs = v; } else if (os_strcmp(pos, "cwmin") == 0) { v = atoi(val); if (v < 0 || v > 12) { wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v); return -1; } ac->cwmin = v; } else if (os_strcmp(pos, "cwmax") == 0) { v = atoi(val); if (v < 0 || v > 12) { wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v); return -1; } ac->cwmax = v; } else if (os_strcmp(pos, "txop_limit") == 0) { v = atoi(val); if (v < 0 || v > 0xffff) { wpa_printf(MSG_ERROR, "Invalid txop value %d", v); return -1; } ac->txopLimit = v; } else if (os_strcmp(pos, "acm") == 0) { v = atoi(val); if (v < 0 || v > 1) { wpa_printf(MSG_ERROR, "Invalid acm value %d", v); return -1; } ac->admission_control_mandatory = v; } else { wpa_printf(MSG_ERROR, "Unknown wme_ac_ field '%s'", pos); return -1; } return 0;}#ifdef CONFIG_IEEE80211Rstatic int add_r0kh(struct hostapd_bss_config *bss, char *value){ struct ft_remote_r0kh *r0kh; char *pos, *next; r0kh = os_zalloc(sizeof(*r0kh)); if (r0kh == NULL) return -1; /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */ pos = value; next = os_strchr(pos, ' '); if (next) *next++ = '\0'; if (next == NULL || hwaddr_aton(pos, r0kh->addr)) { wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos); os_free(r0kh); return -1; } pos = next; next = os_strchr(pos, ' '); if (next) *next++ = '\0'; if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) { wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos); os_free(r0kh); return -1; } r0kh->id_len = next - pos - 1; os_memcpy(r0kh->id, pos, r0kh->id_len); pos = next; if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) { wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos); os_free(r0kh); return -1; } r0kh->next = bss->r0kh_list; bss->r0kh_list = r0kh; return 0;}static int add_r1kh(struct hostapd_bss_config *bss, char *value){ struct ft_remote_r1kh *r1kh; char *pos, *next; r1kh = os_zalloc(sizeof(*r1kh)); if (r1kh == NULL) return -1; /* 02:01:02:03:04:05 02:01:02:03:04:05 * 000102030405060708090a0b0c0d0e0f */ pos = value; next = os_strchr(pos, ' '); if (next) *next++ = '\0'; if (next == NULL || hwaddr_aton(pos, r1kh->addr)) { wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos); os_free(r1kh); return -1; } pos = next; next = os_strchr(pos, ' '); if (next) *next++ = '\0'; if (next == NULL || hwaddr_aton(pos, r1kh->id)) { wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos); os_free(r1kh); return -1; } pos = next; if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) { wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos); os_free(r1kh); return -1; } r1kh->next = bss->r1kh_list; bss->r1kh_list = r1kh; return 0;}#endif /* CONFIG_IEEE80211R */#ifdef CONFIG_IEEE80211Nstatic int hostapd_config_ht_capab(struct hostapd_config *conf, const char *capab){ if (os_strstr(capab, "[LDPC]")) conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP; if (os_strstr(capab, "[HT40-]")) { conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; conf->secondary_channel = -1; } if (os_strstr(capab, "[HT40+]")) { conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; conf->secondary_channel = 1; } if (os_strstr(capab, "[SMPS-STATIC]")) { conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC; } if (os_strstr(capab, "[SMPS-DYNAMIC]")) { conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC; } if (os_strstr(capab, "[GF]")) conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD; if (os_strstr(capab, "[SHORT-GI-20]")) conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ; if (os_strstr(capab, "[SHORT-GI-40]")) conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ; if (os_strstr(capab, "[TX-STBC]")) conf->ht_capab |= HT_CAP_INFO_TX_STBC; if (os_strstr(capab, "[RX-STBC1]")) { conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; conf->ht_capab |= HT_CAP_INFO_RX_STBC_1; } if (os_strstr(capab, "[RX-STBC12]")) { conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; conf->ht_capab |= HT_CAP_INFO_RX_STBC_12; } if (os_strstr(capab, "[RX-STBC123]")) { conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; conf->ht_capab |= HT_CAP_INFO_RX_STBC_123; } if (os_strstr(capab, "[DELAYED-BA]")) conf->ht_capab |= HT_CAP_INFO_DELAYED_BA; if (os_strstr(capab, "[MAX-AMSDU-7935]")) conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE; if (os_strstr(capab, "[DSSS_CCK-40]")) conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ; if (os_strstr(capab, "[PSMP]")) conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP; if (os_strstr(capab, "[LSIG-TXOP-PROT]")) conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT; return 0;}#endif /* CONFIG_IEEE80211N *//** * hostapd_config_read - Read and parse a configuration file * @fname: Configuration file name (including path, if needed) * Returns: Allocated configuration data structure */struct hostapd_config * hostapd_config_read(const char *fname){ struct hostapd_config *conf; struct hostapd_bss_config *bss; FILE *f; char buf[256], *pos; int line = 0; int errors = 0; int pairwise; size_t i; f = fopen(fname, "r"); if (f == NULL) { wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " "for reading.", fname); return NULL; } conf = hostapd_config_defaults(); if (conf == NULL) { fclose(f); return NULL; } bss = conf->last_bss = conf->bss; while (fgets(buf, sizeof(buf), f)) { bss = conf->last_bss; line++; if (buf[0] == '#') continue; pos = buf; while (*pos != '\0') { if (*pos == '\n') { *pos = '\0'; break; } pos++; } if (buf[0] == '\0') continue; pos = os_strchr(buf, '='); if (pos == NULL) { wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'", line, buf); errors++; continue; } *pos = '\0'; pos++; if (os_strcmp(buf, "interface") == 0) { os_strlcpy(conf->bss[0].iface, pos, sizeof(conf->bss[0].iface)); } else if (os_strcmp(buf, "bridge") == 0) { os_strlcpy(bss->bridge, pos, sizeof(bss->bridge)); } else if (os_strcmp(buf, "driver") == 0) { int i; /* clear to get error below if setting is invalid */ conf->driver = NULL; for (i = 0; hostapd_drivers[i]; i++) { if (os_strcmp(pos, hostapd_drivers[i]->name) == 0) { conf->driver = hostapd_drivers[i]; break; } } if (conf->driver == NULL) { wpa_printf(MSG_ERROR, "Line %d: invalid/" "unknown driver '%s'", line, pos); errors++; } } else if (os_strcmp(buf, "debug") == 0) { wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' " "configuration variable is not used " "anymore", line); } else if (os_strcmp(buf, "logger_syslog_level") == 0) { bss->logger_syslog_level = atoi(pos); } else if (os_strcmp(buf, "logger_stdout_level") == 0) { bss->logger_stdout_level = atoi(pos); } else if (os_strcmp(buf, "logger_syslog") == 0) { bss->logger_syslog = atoi(pos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -