Пример #1
0
/**
 * @brief Implements the MLME-ORPHAN.response
 *
 * The MLME-ORPHAN.response primitive allows the next higher layer
 * of a coordinator to respond to the MLME-ORPHAN.indication primitive.
 * The MLME-ORPHAN.response primitive is generated by the next higher
 * layer and issued to its MLME when it reaches a decision about whether
 * the orphaned device indicated in the MLME-ORPHAN.indication primitive
 * is associated.
 *
 * @param m Pointer to the message.
 */
void mlme_orphan_response(uint8_t *m)
{
	bool transmission_status = mac_tx_coord_realignment_command(
			ORPHANREALIGNMENT,
			(buffer_t *)m,
			tal_pib.PANId,
			tal_pib.CurrentChannel,
			tal_pib.CurrentPage);

	if (!transmission_status) {
		mac_mlme_comm_status(MAC_CHANNEL_ACCESS_FAILURE,
				(buffer_t *)m);
	}
}
Пример #2
0
/**
 * @brief The MLME-START.request primitive makes a request for the device to
 * start using a new superframe configuration
 *
 * @param m Pointer to MLME_START.request message issued by the NHLE
 */
void mlme_start_request(uint8_t *m)
{
    mlme_start_req_t *msg = (mlme_start_req_t *)BMM_BUFFER_POINTER((buffer_t *)m);

    /*
     * The MLME_START.request parameters are copied into a global variable
     * structure, which is used by check_start_parameter() function.
     */
    memcpy(&msr_params, msg, sizeof(msr_params));

    if (BROADCAST == tal_pib.ShortAddress)
    {
        /*
         * The device is void of short address. This device cannot start a
         * network, hence a confirmation is given back.
         */
        gen_mlme_start_conf((buffer_t *)m, MAC_NO_SHORT_ADDRESS);
        return;
    }

#ifndef REDUCED_PARAM_CHECK
    if (!check_start_parameter(msg))
    {
        /*
         * The MLME_START.request parameters are invalid, hence confirmation
         * is given to NHLE.
         */
        gen_mlme_start_conf((buffer_t *)m, MAC_INVALID_PARAMETER);
    }
    else
#endif  /* REDUCED_PARAM_CHECK */
    {
        /*
         * All the start parameters are valid, hence MLME_START.request can
         * proceed.
         */
        set_tal_pib_internal(mac_i_pan_coordinator,
                             (void *)&(msg->PANCoordinator));

        if (msr_params.CoordRealignment)
        {
            /* First inform our devices of the configuration change */
            if (!mac_tx_coord_realignment_command(COORDINATORREALIGNMENT,
                                                  (buffer_t *)m,
                                                  msr_params.PANId,
                                                  msr_params.LogicalChannel,
                                                  msr_params.ChannelPage))
            {
                /*
                 * The coordinator realignment command was unsuccessful,
                 * hence the confiramtion is given to NHLE.
                 */
                gen_mlme_start_conf((buffer_t *)m, MAC_INVALID_PARAMETER);
            }
        }
        else
        {
            /* This is a normal MLME_START.request. */
            retval_t channel_set_status, channel_page_set_status;

            /* The new PIBs are set at the TAL. */
            set_tal_pib_internal(macBeaconOrder, (void *)&(msg->BeaconOrder));

            /* If macBeaconOrder is equal to 15, set also macSuperframeOrder to 15. */
            if (msg->BeaconOrder == NON_BEACON_NWK)
            {
                msg->SuperframeOrder = NON_BEACON_NWK;
            }

            set_tal_pib_internal(macSuperframeOrder, (void *)&(msg->SuperframeOrder));

#ifdef BEACON_SUPPORT
            /*
             * Symbol times are calculated according to the new BO and SO
             * values.
             */
            if (tal_pib.BeaconOrder < NON_BEACON_NWK)
            {
                set_tal_pib_internal(macBattLifeExt,
                                     (void *)&(msr_params.BatteryLifeExtension));
            }
#endif /* BEACON_SUPPORT */

            /* Wake up radio first */
            mac_trx_wakeup();

            /* MLME_START.request parameters other than BO and SO are set at TAL */
            set_tal_pib_internal(macPANId, (void *)&(msr_params.PANId));

            channel_page_set_status =
                set_tal_pib_internal(phyCurrentPage,
                                     (void *)&(msr_params.ChannelPage));

            channel_set_status =
                set_tal_pib_internal(phyCurrentChannel,
                                     (void *)&(msr_params.LogicalChannel));

            set_tal_pib_internal(mac_i_pan_coordinator,
                                 (void *)&(msr_params.PANCoordinator));

            if ((MAC_SUCCESS == channel_page_set_status) &&
                (MAC_SUCCESS == channel_set_status) &&
                (PHY_RX_ON == tal_rx_enable(PHY_RX_ON))
               )
            {
                if (msr_params.PANCoordinator)
                {
                    mac_state = MAC_PAN_COORD_STARTED;
                }
                else
                {
                    mac_state = MAC_COORDINATOR;
                }

                gen_mlme_start_conf((buffer_t *)m, MAC_SUCCESS);

#ifdef BEACON_SUPPORT
                /*
                 * In case we have a beaconing network, the beacon timer needs
                 * to be started now.
                 */
                if (tal_pib.BeaconOrder != NON_BEACON_NWK)
                {
                    mac_start_beacon_timer();
                }
#endif  /* BEACON_SUPPORT */
            }
            else
            {
                /* Start of network failed. */
                gen_mlme_start_conf((buffer_t *)m, MAC_INVALID_PARAMETER);
            }

            /* Set radio to sleep if allowed */
            mac_sleep_trans();
        }
    }
}