Exemplo n.º 1
0
/**
 * \brief Performs a Reset check on AT86RFx module
 *
 * This function will simply test the output of the function
 * \ref wpan_mlme_reset_req and returns an error in case of failure.
 *
 * \param test Current test case.
 */
static void run_wpan_reset_test(const struct test_case *test)
{
	wpan_mlme_reset_req(true);
	while (!wpan_reset_conf_rcvd) {
		wpan_task();
	}
	test_assert_true(test, wpan_reset_conf_status == MAC_SUCCESS,
			"AVR2025_MAC - MAC Reset request failed");
}
Exemplo n.º 2
0
/*! \brief Main function.
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	irq_initialize_vectors();
	board_init();
	sysclk_init();

	sw_timer_init();

	if(MAC_SUCCESS != wpan_init())
	{
        /*
         * Stay here; we need a valid IEEE address.
         * Check kit documentation how to create an IEEE address
         * and to store it into the EEPROM.
         */
		app_alert();
	}

    /* Initialize LEDs. */
    LED_On(LED_START);         // indicating application is started
    LED_Off(LED_NWK_SETUP);    // indicating node is associated
    LED_Off(LED_DATA);         // indicating successfull data transmission

	cpu_irq_enable();

	sw_timer_get_id(&TIMER_LED_OFF);
	sw_timer_get_id(&WAKE_TIMER);

	node_status = COLD_START_RESET;

    /*
     * Reset the MAC layer to the default values
     * This request will cause a mlme reset confirm message ->
     * usr_mlme_reset_conf
     */
    wpan_mlme_reset_req(true);

    /* Main loop */
	while (true)
	{
		wpan_task();
        app_task(); /* Application task */
	}
}
Exemplo n.º 3
0
/**
 * @brief Main function of the device application
 */
int main(void)
{
	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	irq_initialize_vectors();
	board_init();
	sysclk_init();

	sw_timer_init();

	if(MAC_SUCCESS != wpan_init())
	{
		app_alert();
	}

    /* Initialize LEDs. */
    LED_On(LED_START);         // indicating application is started
    LED_Off(LED_NWK_SETUP);    // indicating node is associated
    LED_Off(LED_DATA);         // indicating successfull data transmission

	cpu_irq_enable();

#ifdef SIO_HUB
    /* Initialize the serial interface used for communication with terminal program. */
   sio2host_init();

    /* To make sure the hyper terminal gets connected to the system */
    sio2host_getchar();

    printf("\nNobeacon_Application\r\n\n");
    printf("\nDevice\r\n\n");
#endif /* SIO_HUB */

	sw_timer_get_id(&APP_TIMER_LED_OFF);
	sw_timer_get_id(&APP_TIMER_POLL_DATA);

	wpan_mlme_reset_req(true);

	while (true)
	{
		wpan_task();
	}
}
void usr_mlme_set_conf(uint8_t status, uint8_t PIBAttribute,
		uint8_t PIBAttributeIndex)
{
	if (status != MAC_SUCCESS) {
		/* something went wrong; restart */
		wpan_mlme_reset_req(true);
	} else {
		if (mlme_set_conf_run_time) {
			usr_mlme_set_conf_run_time(status, PIBAttribute,
					PIBAttributeIndex);
			return;
		} else {
			init_secuity_pib(PIBAttribute, PIBAttributeIndex);
		}
	}

	/* Keep compiler happy. */
	PIBAttributeIndex = PIBAttributeIndex;
}
Exemplo n.º 5
0
/** @brief Callback function usr_mlme_set_conf
 *
 *  @param status        Result of requested PIB attribute set operation
 *  @param PIBAttribute  Updated PIB attribute
 *
 */
void usr_mlme_set_conf(uint8_t status, uint8_t PIBAttribute,
		uint8_t PIBAttributeIndex)
{
	if (status != MAC_SUCCESS) {
		/* something went wrong with mlme set request; restart */
		wpan_mlme_reset_req(true);
	} else {
		if (mlme_set_conf_run_time) {
			/* post initialization security pib callback */
			usr_mlme_set_conf_run_time(status, PIBAttribute,
					PIBAttributeIndex);
		} else {
			/* Initialize the mac security PIB before starting the
			 * network */
			init_secuity_pib(PIBAttribute, PIBAttributeIndex);
		}
	}

	/* Keep compiler happy. */
	PIBAttributeIndex = PIBAttributeIndex;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
/**
 * @brief Main function of the coordinator application
 *
 * This function initializes the MAC, initiates a MLME reset request
 * (@ref wpan_mlme_reset_req()), and implements a the main loop.
 */
int main(void)
{	
	irq_initialize_vectors();
	#if SAMD20
	system_init();
	delay_init();
	#else
	sysclk_init();

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	#endif
	#ifdef SIO_HUB
		sio2host_init();
	#endif
	sw_timer_init();

	if (MAC_SUCCESS != wpan_init()) {
		app_alert();
	}

	/* Initialize LEDs. */
	LED_On(LED_START);     /* indicating application is started */
	LED_Off(LED_NWK_SETUP); /* indicating network is started */
	LED_Off(LED_DATA);     /* indicating data transmission */

	cpu_irq_enable();

#ifdef SIO_HUB
	/* Initialize the serial interface used for communication with terminal
	 *program. */

	/* To make sure the Hyper Terminal Connected to the system*/
	sio2host_getchar();

#ifdef BEACON_SUPPORT
printf("\nBeacon_Application\r\n\n");
#else
printf("\nNO Beacon_Application\r\n\n");
#endif
	printf("\nCoordinator\r\n\n");
	print_stack_app_build_features();
#endif /* SIO_HUB */

	sw_timer_get_id(&APP_TIMER_INDIRECT_DATA);
	sw_timer_get_id(&APP_TIMER_BCN_PAYLOAD_UPDATE);
	sw_timer_get_id(&APP_TIMER_BC_DATA);
	#ifdef GTS_SUPPORT
	sw_timer_get_id(&APP_TIMER_GTS_DATA);
    #endif
	/*
	 * Reset the MAC layer to the default values.
	 * This request will cause a mlme reset confirm message ->
	 * usr_mlme_reset_conf
	 */
	wpan_mlme_reset_req(true);

#ifdef GPIO_PUSH_BUTTON_0
	dst_addr.AddrMode = 2;
	dst_addr.PANId = DEFAULT_PAN_ID;
#endif /* GPIO_PUSH_BUTTON_0 */

	while (true) {
		wpan_task();
#ifdef GPIO_PUSH_BUTTON_0
		if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) {
			delay_ms(DEBOUNCE_DELAY_MS);
			if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_0)) {
				dst_addr.Addr.short_address = BROADCAST;
				wpan_mcps_data_req(FCF_SHORT_ADDR, &dst_addr,
						strlen(broadcast_payload),
						(uint8_t *)&broadcast_payload, 1,
						WPAN_TXOPT_OFF);
			}
		}

#endif /* GPIO_PUSH_BUTTON_0 */
	}
}
/*
 * @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;
}
Exemplo n.º 9
0
/**
 * @brief Main function of the device application
 */
int main(void)
{
    irq_initialize_vectors();
#if SAMD || SAMR21
    system_init();
    delay_init();
#else
    sysclk_init();

    /* Initialize the board.
     * The board-specific conf_board.h file contains the configuration of
     * the board initialization.
     */
    board_init();
#endif
#ifdef SIO_HUB
    sio2host_init();
#endif
    sw_timer_init();

    if (MAC_SUCCESS != wpan_init()) {
        app_alert();
    }

    /* Initialize LEDs. */
    LED_On(LED_START);     /* indicating application is started */
    LED_Off(LED_NWK_SETUP); /* indicating network is started */
    LED_Off(LED_DATA);     /* indicating data transmission */
    cpu_irq_enable();
#ifdef SIO_HUB

    /* Initialize the serial interface used for communication with terminal
     * program. */

    /* To Make sure the Hyper Terminal to the System */
    sio2host_getchar();

    printf("\nBeacon_Application\r\n\n");
    printf("\nDevice\r\n\n");
    print_stack_app_build_features();
#endif

    sw_timer_get_id(&APP_TIMER);

    wpan_mlme_reset_req(true);
#ifdef ENABLE_SLEEP
    sw_timer_get_id(&APP_TIMER_SLEEP);
#endif
    LED_Off(LED_NWK_SETUP);
    while (true) {
        wpan_task();
#if (defined ENABLE_SLEEP || defined RTC_SLEEP)
        /* Requesting MAC for Sleep Duration*/
        sleep_time = mac_ready_to_sleep();
        if ((sleep_time > (uint32_t)APP_GUARD_TIME_US)) {
            /*Entering Power save Mode when the sleep duration is
             * above the guard time*/
            enter_sleep(sleep_time);
        }
#endif
    }
}