int ibss_rsn_start(struct ibss_rsn *ibss_rsn, const u8 *addr) { struct ibss_rsn_peer *peer; if (ibss_rsn == NULL) return -1; for (peer = ibss_rsn->peers; peer; peer = peer->next) { if (os_memcmp(addr, peer->addr, ETH_ALEN) == 0) { wpa_printf(MSG_DEBUG, "RSN: IBSS Authenticator and " "Supplicant for peer " MACSTR " already " "running", MAC2STR(addr)); return 0; } } wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Authenticator and " "Supplicant for peer " MACSTR, MAC2STR(addr)); peer = os_zalloc(sizeof(*peer)); if (peer == NULL) return -1; peer->ibss_rsn = ibss_rsn; os_memcpy(peer->addr, addr, ETH_ALEN); if (ibss_rsn_supp_init(peer, ibss_rsn->wpa_s->own_addr, ibss_rsn->psk) < 0) { ibss_rsn_free(peer); return -1; } if (ibss_rsn_auth_init(ibss_rsn, peer) < 0) { ibss_rsn_free(peer); return -1; } peer->next = ibss_rsn->peers; ibss_rsn->peers = peer; return 0; }
void ibss_rsn_stop(struct ibss_rsn *ibss_rsn, const u8 *peermac) { struct ibss_rsn_peer *peer, *prev; if (ibss_rsn == NULL) return; if (peermac == NULL) { /* remove all peers */ wpa_printf(MSG_DEBUG, "%s: Remove all peers", __func__); peer = ibss_rsn->peers; while (peer) { prev = peer; peer = peer->next; ibss_rsn_free(prev); ibss_rsn->peers = peer; } } else { /* remove specific peer */ wpa_printf(MSG_DEBUG, "%s: Remove specific peer " MACSTR, __func__, MAC2STR(peermac)); for (prev = NULL, peer = ibss_rsn->peers; peer != NULL; prev = peer, peer = peer->next) { if (os_memcmp(peermac, peer->addr, ETH_ALEN) == 0) { if (prev == NULL) ibss_rsn->peers = peer->next; else prev->next = peer->next; ibss_rsn_free(peer); wpa_printf(MSG_DEBUG, "%s: Successfully " "removed a specific peer", __func__); break; } } } }
void ibss_rsn_deinit(struct ibss_rsn *ibss_rsn) { struct ibss_rsn_peer *peer, *prev; if (ibss_rsn == NULL) return; peer = ibss_rsn->peers; while (peer) { prev = peer; peer = peer->next; ibss_rsn_free(prev); } wpa_deinit(ibss_rsn->auth_group); os_free(ibss_rsn); }
static struct ibss_rsn_peer * ibss_rsn_peer_init(struct ibss_rsn *ibss_rsn, const u8 *addr) { struct ibss_rsn_peer *peer; if (ibss_rsn == NULL) return NULL; peer = ibss_rsn_get_peer(ibss_rsn, addr); if (peer) { wpa_printf(MSG_DEBUG, "RSN: IBSS Supplicant for peer "MACSTR " already running", MAC2STR(addr)); return peer; } wpa_printf(MSG_DEBUG, "RSN: Starting IBSS Supplicant for peer "MACSTR, MAC2STR(addr)); peer = os_zalloc(sizeof(*peer)); if (peer == NULL) { wpa_printf(MSG_DEBUG, "RSN: Could not allocate memory."); return NULL; } peer->ibss_rsn = ibss_rsn; os_memcpy(peer->addr, addr, ETH_ALEN); peer->authentication_status = IBSS_RSN_AUTH_NOT_AUTHENTICATED; if (ibss_rsn_supp_init(peer, ibss_rsn->wpa_s->own_addr, ibss_rsn->psk) < 0) { ibss_rsn_free(peer); return NULL; } peer->next = ibss_rsn->peers; ibss_rsn->peers = peer; return peer; }