/** * @file * This file implements the MLME-POLL.request (MAC layer management entity) * entry points. * * $Id: poll.c,v 1.39.2.3 2007/06/15 08:06:35 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 "phy.h" #include "mac.h" #include "timer_const.h" #if APP_TYPE >= APP_L2 || defined(DOXGEN) /* === Globals ============================================================= */ /* === Prototypes ========================================================== */ /* === Implementation ====================================================== */ /* * Internal function to initiate mlme poll confirm message */ static void gen_mlme_poll_conf(uint8_t status) { mlme_poll_conf_t mpc; mpc.cmdcode = MLME_POLL_CONFIRM; mpc.size = sizeof(mlme_poll_conf_t) - sizeof(mpc.size); mpc.status = status; // only go to sleep if poll was not successfull, // otherwise stay awake until subsequent evaluation of data frame if (status != MAC_SUCCESS) { // go to sleep? if(!mac_pib_macRxOnWhenIdle) { // set sleep=true mac_phy_init_sleep(); } } bios_pushback_event((uint8_t *)&mpc); } /** * \brief Implement MLME-POLL.request * * The MLME-POLL.request primitive is generated by the next higher layer and issued to its MLME when * data are to be requested from a coordinator. * * @param m Pointer to the message */ void mlme_poll_request(uint8_t *m) { mac_original_state = mac_state; if ((mac_state == MAC_A) || (mac_state == MAC_Tracking_Beacon)) { // do we need to wake up the radio first? if (mac_radio_sleep_state == RADIO_SLEEPING) { mac_state = MAC_WAKEUP_POLL; // wake up radio first mac_phy_wakeup(); } else { mac_awake_poll(); } } else { gen_mlme_poll_conf(MAC_CHANNEL_ACCESS_FAILURE); } } /** * @brief Continues handling of MLME-POLL.request once the radio is awake */ void mac_awake_poll(void) { // set the MAC to it's original state mac_state = mac_original_state; // Build command frame due to explicit poll request mac_build_data_req_cmd(true, false); } /** * \brief T_MaxFrameResponseTime timer callback * * This function implements the T_MaxFrameResponseTime timer callback. If a poll request is pending, * a mlme-poll-confirm is generated. The mac state is set to mac_pre_csmaca_state. * No data is returned on poll request. */ void mac_t_maxframeresponsetime(void) { if (mac_state == MAC_H) { gen_mlme_poll_conf(MAC_NO_DATA); } if ((mac_state == MAC_H) || (mac_state == MAC_await_frame)) { mac_state = mac_pre_csmaca_state; } } /** * \brief process a data response to an MLME-POLL.request * * In response to an MLME-POLL.request, our coordinator responded with * a frame. See whether we've got any data, and construct the * appropriate MLME-POLL.confirm message. */ void mac_process_data_response(void) { uint8_t status = MAC_SUCCESS; switch (mac_parse_data.frame_type) { case FCF_FRAMETYPE_MAC_CMD: // We probably received an Association Response or // Disassociation Notification frame status = MAC_NO_DATA; break; case FCF_FRAMETYPE_DATA: if (mac_parse_data.payload_length > 0) { status = MAC_SUCCESS; /* MCPS-DATA.indication is generated in mac_proc_pd_data_ind() */ } else { status = MAC_NO_DATA; } break; default: // unexpected frame type, do nothing // actually return immediately (a "break" would be wrong here), // since all subsequent actions are not to be done now // instead the timer will expire and initiate the proper stuff return; } gen_mlme_poll_conf(status); bios_stoptimer(T_MaxFrameResponseTime); mac_state = mac_pre_csmaca_state; } #endif /* APP_TYPE >= APP_L2 || defined(DOXYGEN)*/ /* EOF */