/* * @brief Callback function usr_mlme_comm_status_ind * * @param SrcAddrSpec Pointer to source address specification * @param DstAddrSpec Pointer to destination address specification * @param status Result for related response operation */ void usr_mlme_comm_status_ind(wpan_addr_spec_t *SrcAddrSpec, wpan_addr_spec_t *DstAddrSpec, uint8_t status) { if (status == MAC_SUCCESS) { #if (defined MAC_SECURITY_ZIP) || (defined MAC_SECURITY_2006) recent_assoc_dev_no++; wpan_mlme_set_req(macDeviceTableEntries, NO_PIB_INDEX, &no_of_assoc_devices); wpan_mlme_get_req(macKeyTable, recent_assoc_dev_no); #endif /* * Now the association of the device has been successful and its * information, like address, could be stored. * But for the sake of simple handling it has been done * during assignment of the short address within the function * assign_new_short_addr() */ /* Start timer to initiate indirect data transmission. */ sw_timer_start(APP_TIMER_INDIRECT_DATA, ((uint32_t)APP_INDIRECT_DATA_DURATION_MS * 1000), SW_TIMEOUT_RELATIVE, (FUNC_PTR)indirect_data_cb, NULL); } else { } /* Keep compiler happy. */ SrcAddrSpec = SrcAddrSpec; DstAddrSpec = DstAddrSpec; }
/* * Callback function usr_mlme_get_conf * * @param status Result of requested PIB attribute get operation. * @param PIBAttribute Retrieved PIB attribute. * @param PIBAttributeIndex Index of the PIB attribute to be read. * @param PIBAttributeValue Pointer to data containing retrieved PIB attribute, * * @return void */ void usr_mlme_get_conf(uint8_t status, uint8_t PIBAttribute, #if (defined MAC_SECURITY_ZIP) || (defined MAC_SECURITY_2006) uint8_t PIBAttributeIndex, #endif void *PIBAttributeValue) { #if (defined MAC_SECURITY_ZIP) || (defined MAC_SECURITY_2006) mac_key_table_t *key_table = (mac_key_table_t *)PIBAttributeValue; #endif if ((status == MAC_SUCCESS) && (PIBAttribute == phyCurrentPage)) { #ifdef HIGH_DATA_RATE_SUPPORT current_channel_page = 17; #else current_channel_page = *(uint8_t *)PIBAttributeValue; #endif wpan_mlme_get_req(phyChannelsSupported #if (defined MAC_SECURITY_ZIP) || (defined MAC_SECURITY_2006) ,0 #endif ); } else if ((status == MAC_SUCCESS) && (PIBAttribute == phyChannelsSupported)) { uint8_t index; channels_supported = convert_byte_array_to_32_bit(PIBAttributeValue); for (index = 0; index < 32; index++) { if (channels_supported & (1 << index)) { current_channel = index + CHANNEL_OFFSET; break; } } /* * Set the short address of this node. * Use: bool wpan_mlme_set_req(uint8_t PIBAttribute, * void *PIBAttributeValue); * * This request leads to a set confirm message -> *usr_mlme_set_conf */ /* MAC Short Address will be set after setting the Security PIB's */ #if (defined MAC_SECURITY_ZIP) || (defined MAC_SECURITY_2006) /* Set security PIB attributes now. */ wpan_mlme_set_req(macDefaultKeySource, NO_PIB_INDEX, &default_key_source); #else uint8_t short_addr[2]; short_addr[0] = (uint8_t)COORD_SHORT_ADDR; /* low byte */ short_addr[1] = (uint8_t)(COORD_SHORT_ADDR >> 8); /* high byte */ wpan_mlme_set_req(macShortAddress, short_addr); #endif /* (defined MAC_SECURITY_ZIP) || (defined MAC_SECURITY_2006) */ }
/* * @brief Callback function usr_mlme_set_conf * * @param status Result of requested PIB attribute set operation * @param PIBAttribute Updated PIB attribute */ static void usr_mlme_set_conf_run_time(uint8_t status, uint8_t PIBAttribute, uint8_t PIBAttributeIndex) { if (status != MAC_SUCCESS) { /* something went wrong; restart */ wpan_mlme_reset_req(true); } else { switch (PIBAttribute) { case macPANId: { /* * Set the Coordinator Short Address of the scanned * network. * This is required in order to perform a proper sync * before association. */ wpan_mlme_set_req(macCoordShortAddress, NO_PIB_INDEX, &coord_addr_spec.Addr); } break; case macCoordShortAddress: { #ifdef BEACON_SUPPORT wpan_mlme_sync_req(current_channel, current_channel_page, 1); #endif /* BEACON_SUPPORT */ } break; case macDefaultKeySource: { uint8_t mac_sec_level_table_entries = DEFAULT_MAC_SEC_LVL_TABLE_ENTRIES; wpan_mlme_set_req(macSecurityLevelTableEntries, NO_PIB_INDEX, &mac_sec_level_table_entries); } break; case macSecurityLevelTableEntries: { uint8_t mac_sec_level_table[4] = {FRAME_TYPE_DATA, /* * *FrameType: * *Data **/ CMD_FRAME_ID_NA, /* * *CommandFrameIdentifier: * *N/A **/ /* ZIP_SEC_MIN, * // * SecurityMinimum: 5 **/ 0X05, DEV_OVERRIDE_SEC_MIN /* * *DeviceOverrideSecurityMinimum: * *True **/ }; wpan_mlme_set_req(macSecurityLevelTable, INDEX_0, /* Index: 0 */ &mac_sec_level_table); } break; case macSecurityLevelTable: { uint8_t mac_key_table_entries = DEFAULT_MAC_KEY_TABLE_ENTRIES; wpan_mlme_set_req(macKeyTableEntries, NO_PIB_INDEX, &mac_key_table_entries); } break; case macKeyTableEntries: { uint8_t mac_key_table[43] = { default_key_source[0], /* * *LookupData[0] **/ default_key_source[1], /* * *LookupData[1] **/ default_key_source[2], /* * *LookupData[2] **/ default_key_source[3], /* * *LookupData[3] **/ default_key_source[4], /* * *LookupData[4] **/ default_key_source[5], /* * *LookupData[5] **/ default_key_source[6], /* * *LookupData[6] **/ default_key_source[7], /* * *LookupData[7] **/ KEY_INDEX_0, /* * *LookupData[8] **/ LOOKUP_DATA_SIZE_1, /* * *LookupDataSize: * 0x01 : * Size 9 * octets */ MAC_ZIP_MAX_KEY_ID_LOOKUP_LIST_ENTRIES, /* * *KeyIdLookupListEntries * *= * *1 **/ /* KeyDeviceList[1] */ DEV_DESC_HANDLE_IDX_0, /* * *DeviceDescriptorHandle **/ true, /* * *UniqueDevice **/ false, /* * *Blacklisted **/ DEV_DESC_HANDLE_IDX_0, /* * *DeviceDescriptorHandle **/ true, /* * *UniqueDevice **/ false, /* * *Blacklisted **/ DEV_DESC_HANDLE_IDX_0, /* * *DeviceDescriptorHandle **/ true, /* * *UniqueDevice **/ false, /* * *Blacklisted **/ DEV_DESC_HANDLE_IDX_0, /* * *DeviceDescriptorHandle **/ true, /* * *UniqueDevice **/ false, /* * *Blacklisted **/ MAC_ZIP_MAX_KEY_DEV_LIST_ENTRIES, /* * *KeyDeviceListEntries **/ /* KeyUsageList */ FRAME_TYPE_BEACON, /* * *FrameType * - * Beacon * frames **/ CMD_FRAME_ID_NA, /* * *CommandFrameIdentifier * not used * in ZIP */ MAC_ZIP_MAX_KEY_USAGE_LIST_ENTRIES, /* * *KeyUsageListEntries **/ /* Key */ default_key[3][0], default_key[3][1], default_key[3][2], default_key[3][3], default_key[3][4], default_key[3][5], default_key[3][6], default_key[3][7], default_key[3][8], default_key[3][9], default_key[3][10], default_key[3][11], default_key[3][12], default_key[3][13], default_key[3][14], default_key[3][15], }; wpan_mlme_set_req(macKeyTable, INDEX_3, /* Index: 3 */ &mac_key_table); } break; case macKeyTable: { /* * Sync with beacon frames from our coordinator. * Use: bool wpan_mlme_sync_req(uint8_t LogicalChannel, * uint8_t ChannelPage, * bool TrackBeacon); * * This does not lead to an immediate reaction. * * In case we receive beacon frames from our coordinator * including * a beacon payload, this is indicated in the callback * function * usr_mlme_beacon_notify_ind(). * * In case the device cannot find its coordinator or * later * looses * synchronization with its parent, this is indicated in * the * callback function usr_mlme_sync_loss_ind(). */ if (PIBAttributeIndex == INDEX_3 && app_state == APP_IDLE) { wpan_mlme_get_req(phyCurrentPage, NO_PIB_INDEX); } } break; case macDeviceTableEntries: { uint8_t mac_dev_table[17] = { /* DeviceDescriptor */ /* PANId */ (uint8_t)DEFAULT_PAN_ID, (uint8_t)(DEFAULT_PAN_ID >> 8), /* Device ShortAddress */ (uint8_t)COORD_SHORT_ADDR, (uint8_t)(COORD_SHORT_ADDR >> 8), /* Device ExtAddress */ COORD_IEEE_ADDRESS[7], COORD_IEEE_ADDRESS[6], COORD_IEEE_ADDRESS[5], COORD_IEEE_ADDRESS[4], COORD_IEEE_ADDRESS[3], COORD_IEEE_ADDRESS[2], COORD_IEEE_ADDRESS[1], COORD_IEEE_ADDRESS[0], /* FrameCounter */ 0, 0, 0, 0, /* Exempt */ 0 }; wpan_mlme_set_req(macDeviceTable, INDEX_0, /* Index: 0 */ &mac_dev_table); } break; case macDeviceTable: { /* Use DSN start value as in ZIP test spec. */ uint8_t new_dsn = 0x0; wpan_mlme_set_req(macDSN, NO_PIB_INDEX, &new_dsn); } break; case macDSN: { /* Use DSN start value as in ZIP test spec. */ uint32_t frame_counter = 1; wpan_mlme_set_req(macFrameCounter, NO_PIB_INDEX, &frame_counter); } break; case macFrameCounter: { wpan_mlme_get_req(macKeyTable, deviceShortAddress - 1); } break; default: /* undesired PIB attribute; restart */ wpan_mlme_reset_req(true); break; } } /* Keep compiler happy. */ PIBAttributeIndex = PIBAttributeIndex; }