/** * @file * \brief This file implements orphan realignment. * * $Id: orphan.c,v 1.20 2007/05/15 08:48:55 sschneid Exp $ */ /** * \author * Atmel Corporation: http://www.atmel.com * Support email: avr@atmel.com */ /* * Copyright (c) 2006, Atmel Corporation All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The name of ATMEL may not be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* === Includes ============================================================ */ #include #include #include "mac.h" #if APP_TYPE >= APP_L2 || defined (DOXYGEN) /* === Globals ============================================================= */ /* === Prototypes ========================================================== */ /* === Implementation ====================================================== */ #if DEVICE_TYPE == FD1 || DEVICE_TYPE == FD1_NOGTS || defined(DOXYGEN) /** * @brief Handles an orphan notification * * This function processes an incoming orphan notification command. * A PAN coordinator gets to this function through a pd_data.indication message * because a device has sent it an orphan notification. */ void mac_process_orphan_notification(void) { mlme_orphan_ind_t oi; oi.size = sizeof(mlme_orphan_ind_t) - sizeof(oi.size); oi.cmdcode = MLME_ORPHAN_INDICATION; memcpy(&oi.OrphanAddress, &mac_parse_data.src_addr, sizeof(uint64_t)); oi.SecurityUse = false; oi.ACLEntry = MAC_NOACLENTRYFOUND; bios_pushback_event((uint8_t *) &oi); } /** * @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 A pointer to the message. */ void mlme_orphan_response(uint8_t *m) { mlme_orphan_resp_t *or = (mlme_orphan_resp_t *)m; mac_tx_coord_realignment_command(ORPHANREALIGNMENT, or, mac_pib_macPANId, mac_current_channel); } #endif /* DEVICE_TYPE == FD1 || DEVICE_TYPE == FD1_NOGTS || defined(DOXYGEN) */ /** * @brief Implements coordinator realignment * * A PAN coordinator's response to the reception of an orphan notification * command frame or mlme_start.request. The Pan ID, coord. short addres, logical * channel, and the device's new short address will be written to the PIB. * * @param orphan indicates whether the coordinator realignment command was received * as a result of an orphan scan */ void mac_process_coord_realign(bool orphan) { // mlme_scan_conf_t *msc = (mlme_scan_conf_t *)mac_buffer; union { mlme_scan_conf_t msc; plme_set_trx_state_req_t pst; mlme_sync_loss_ind_t msli; plme_set_req_t psr; } u; if (orphan) { // we have received a coordinator realignment during an orphan scan u.msc.size = sizeof(mlme_scan_conf_t) - sizeof(u.msc.size); u.msc.cmdcode = MLME_SCAN_CONFIRM; u.msc.status = MAC_SUCCESS; u.msc.ScanType = MLME_SCAN_TYPE_ORPHAN; u.msc.UnscannedChannels = 0; u.msc.ResultListSize = 0; u.msc.data[0] = 0; /* null result string */ bios_pushback_event((uint8_t *)&u.msc); mac_state = mac_original_state; // are we allowed to sleep ? if (!mac_pib_macRxOnWhenIdle) { // initialize sleep mac_phy_init_sleep(); } // Turn the radio off; u.pst.size = sizeof(plme_set_trx_state_req_t) - sizeof(u.pst.size); u.pst.cmdcode = PLME_SET_TRX_STATE_REQUEST; u.pst.state = PHY_TRX_OFF; bios_pushback_event((uint8_t *)&u.pst); } else { // the coordinator has changed its PAN parameters // report back a sync loss indication u.msli.size = sizeof(mlme_sync_loss_ind_t) - sizeof(u.msli.size); u.msli.cmdcode = MLME_SYNC_LOSS_INDICATION; u.msli.LossReason = MAC_REALIGNMENT; bios_pushback_event((uint8_t *) &u.msli); } // Set the appropriate PIB entries mac_set_panid(mac_parse_data.payload_data.coord_realign_data.pan_id); if (mac_parse_data.payload_data.coord_realign_data.short_addr != BROADCAST) { // Short address only to be set if not broadcast address mac_set_shortaddr(mac_parse_data.payload_data.coord_realign_data.short_addr); } mac_pib_macCoordShortAddress = mac_parse_data.payload_data.coord_realign_data.coord_short_addr; mac_current_channel = mac_parse_data.payload_data.coord_realign_data.logical_channel; // Tell the PHY to set the channel u.psr.size = sizeof(plme_set_req_t) - sizeof(u.psr.size) + sizeof(uint8_t); u.psr.cmdcode = PLME_SET_REQUEST; u.psr.PIBAttribute = phyCurrentChannel; u.psr.data[0] = sizeof(uint8_t); u.psr.data[1] = mac_current_channel; bios_pushback_event((uint8_t *)&u.psr); } #endif // APP_TYPE >= APP_L2 || defined (DOXYGEN) /* EOF */