Example #1
0
static void run_wpan_scan_test(const struct test_case *test)
{
	wpan_mlme_scan_req(MLME_SCAN_TYPE_ACTIVE,
			SCAN_CHANNEL,
			SCAN_DURATION,
			DEFAULT_CHANNEL_PAGE);
	while (!wpan_scan_conf_rcvd) {
		wpan_task();
	}
	test_assert_true(test,
			(wpan_scan_conf_status == MAC_SUCCESS) ||
			(wpan_scan_conf_status == MAC_NO_BEACON),
			"AVR2025_MAC - MAC Scan test failed");
}
Example #2
0
/*
 * @brief Callback function usr_mlme_set_conf will be used after starting the
 * network
 *
 * @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 at mlme set request; restart */
		wpan_mlme_reset_req(true);
	} else {
		switch (PIBAttribute) {
		case macShortAddress:
		{
			/* set the mac association permission */
			uint8_t association_permit = true;

			wpan_mlme_set_req(macAssociationPermit, NO_PIB_INDEX,
					&association_permit);
		}
		break;

		case macAssociationPermit:
		{
			/* Set the MAC Rx on when Idle */
			bool rx_on_when_idle = true;

			wpan_mlme_set_req(macRxOnWhenIdle, NO_PIB_INDEX,
					&rx_on_when_idle);
		}
		break;

		case macRxOnWhenIdle:
		{
			/* Set the beacon payload length. */
			uint8_t beacon_payload_len = BEACON_PAYLOAD_LEN;
			wpan_mlme_set_req(macBeaconPayloadLength, NO_PIB_INDEX,
					&beacon_payload_len);
		}
		break;

		case macBeaconPayloadLength:
		{
			/*
			 * Once the length of the beacon payload has been
			 * defined,
			 * set the actual beacon payload.
			 */
			wpan_mlme_set_req(macBeaconPayload, NO_PIB_INDEX,
					&beacon_payload);
		}
		break;

		case macBeaconPayload:
		{
			if (COORD_STARTING == coord_state) {
				/*
				 * Initiate an active scan over all channels to
				 * determine
				 * which channel to use.
				 * Use: bool wpan_mlme_scan_req(uint8_t
				 * ScanType,
				 *                              uint32_t
				 * ScanChannels,
				 *                              uint8_t
				 * ScanDuration,
				 *                              uint8_t
				 * ChannelPage);
				 *
				 * This request leads to a scan confirm message
				 *->
				 * usr_mlme_scan_conf
				 * Scan for about 50 ms on each channel ->
				 * ScanDuration
				 *= 1
				 * Scan for about 1/2 second on each channel ->
				 * ScanDuration = 5
				 * Scan for about 1 second on each channel ->
				 * ScanDuration = 6
				 */
				wpan_mlme_scan_req(MLME_SCAN_TYPE_ACTIVE,
						SCAN_CHANNEL(current_channel),
						SCAN_DURATION_COORDINATOR,
						current_channel_page);
			}
		}
		break;

		case macDefaultKeySource:
		{
			/* set the maximum no.of mac security level table
			 * entries */
			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:
		{
			/* set the mac security level table for the MAC Data
			 * Security */
			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:
		{
			/* set the maximum no.of key table entries */
			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:
		{
			/* MAC Beacon Frame type default mac key table values */
			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:

			/*
			 * Setting of PIB attributes will continue once a device
			 * has associated successful.
			 */
			break;

		case macDeviceTableEntries:
		{
			/* MAC Device Table entries for the recently associated
			 * device */
			static uint8_t Temp = 0;
			uint8_t mac_dev_table[17];

			/* Temp is used to not update the already device table
			 * again */
			for (uint16_t i = Temp; i < no_of_assoc_devices; i++) {
				mac_dev_table[0]
					= (uint8_t)(DEFAULT_PAN_ID &
						0x00FF);
				mac_dev_table[1]
					= (uint8_t)(DEFAULT_PAN_ID >>
						8);
				mac_dev_table[2]
					= (uint8_t)device_list[i].short_addr;
				mac_dev_table[3]
					= (uint8_t)(device_list[i].short_addr
						>> 8);
				mac_dev_table[4]
					= (uint8_t)device_list[i].ieee_addr;
				mac_dev_table[5]
					= (uint8_t)(device_list[i].ieee_addr
						>> 8);
				mac_dev_table[6]
					= (uint8_t)(device_list[i].ieee_addr
						>> 16);
				mac_dev_table[7]
					= (uint8_t)(device_list[i].ieee_addr
						>> 24);
				mac_dev_table[8]
					= (uint8_t)(device_list[i].ieee_addr
						>> 32);
				mac_dev_table[9]
					= (uint8_t)(device_list[i].ieee_addr
						>> 40);
				mac_dev_table[10]
					= (uint8_t)(device_list[i].ieee_addr
						>> 48);
				mac_dev_table[11]
					= (uint8_t)(device_list[i].ieee_addr
						>> 56);
				mac_dev_table[12] = 0;      /* Initial Frame
					                     * counter value */
				mac_dev_table[13] = 0;
				mac_dev_table[14] = 0;
				mac_dev_table[15] = 0;
				mac_dev_table[16] = 0;      /* Exempt */

				wpan_mlme_set_req(macDeviceTable,
						i, /* Index */
						&mac_dev_table);
			}
			Temp++;
		}
		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:
			break;

		default:
			/* undesired PIB attribute set request; restart */
			wpan_mlme_reset_req(true);
			break;
		}
	}

	/* Keep compiler happy. */
	PIBAttributeIndex = PIBAttributeIndex;
}