bool zigbee_permit_joining(bool join_permitted) { /* Check that the device is operating either as router or coordinator. */ if ((NWK_FORMED != ZIGBEE_NWK_GET_STATE()) && (NWK_STARTED != ZIGBEE_NWK_GET_STATE())) { return false; } /* Set the Associate Permitted flag in the IEEE 802.15.4 MAC. */ IEEE802_15_4_SET_ASSOCIATION_PERMITTED(join_permitted); return true; }
void mac_associate_indication_callback(mlme_associate_ind_t *mai) { /* Allcoate some memory to build the MLME_ASSOCIATE.response on. */ mlme_associate_resp_t *response = (mlme_associate_resp_t *)MEM_ALLOC(mlme_associate_resp_t); if (NULL == response) { return; } memcpy((void *)(&(response->DeviceAddress)), (void *)(&(mai->DeviceAddress)), sizeof(uint64_t)); nwk_param.join_ind.capability_information = mai->CapabilityInformation; /* Check if the device with this long address has been given a short address * already. That is this device is the parent. */ zigbee_neighbor_table_item_t *child = zigbee_neighbor_table_find_long(mai->DeviceAddress); if (NULL != child) { response->AssocShortAddress = child->NetworkAddress; nwk_param.join_ind.allocted_address = child->NetworkAddress; response->status = ASSOCIATION_SUCCESSFUL; } else { /* Check if the joining device is an End device or Router. */ if (((mai->CapabilityInformation) & (0x02)) != (0x02)) { /* Check if it is possible to join the end device. */ child = zigbee_neighbor_table_add_device(); } else { /* Check if it is possible to join the router. */ child = zigbee_neighbor_table_add_router(); } if (NULL == child) { response->AssocShortAddress = 0xFFFF; response->status = PAN_AT_CAPACITY; /* Also upate the permit joining PIB in the IEEE 802.15.4 MAC to * reflect that the system is now not to associate more devices. */ IEEE802_15_4_SET_ASSOCIATION_PERMITTED(false); } else { response->AssocShortAddress = child->NetworkAddress; nwk_param.join_ind.allocted_address = child->NetworkAddress; response->status = ASSOCIATION_SUCCESSFUL; } } (bool)ieee802_15_4_associate_response(response); MEM_FREE(response); }