예제 #1
0
/**
 * @brief Builds the data frame for transmission
 *
 * This function builds the data frame for transmission.
 * The NWK layer has supplied the parameters.
 * The frame_info_t data type is constructed and filled in.
 * Also the FCF is constructed based on the parameters passed.
 *
 * @param msg Pointer to the MCPS-DATA.request parameter
 */
void mcps_data_request(uint8_t *msg)
{
    retval_t status = FAILURE;
    mcps_data_req_t mdr;

    memcpy(&mdr, BMM_BUFFER_POINTER((buffer_t *)msg), sizeof(mcps_data_req_t));

    if ((mdr.TxOptions & WPAN_TXOPT_INDIRECT) == 0)
    {
        /*
         * Data Requests for a coordinator using direct transmission are
         * accepted in all non-transient states (no polling and no scanning
         * is ongoing).
         */
        if ((MAC_POLL_IDLE != mac_poll_state) ||
            (MAC_SCAN_IDLE != mac_scan_state)
           )
        {
            mac_gen_mcps_data_conf((buffer_t *)msg,
                                   (uint8_t)MAC_CHANNEL_ACCESS_FAILURE,
#ifdef ENABLE_TSTAMP
                                   mdr.msduHandle,
                                   0);
#else
                                   mdr.msduHandle);
#endif  /* ENABLE_TSTAMP */
            return;
        }
    }
/*
 * @brief Process tal_tx_frame_done_cb status
 *
 * This function is called, if an ACK is requested in the last transmitted frame.
 * According to the frame type that has previously been sent, the
 * corresponding actions are taken and the MAC returns to its standard state.
 *
 * @param tx_status Status of transmission
 * @param frame Pointer to the transmitted frame
 */
static void mac_process_tal_tx_status(retval_t tx_status,  frame_info_t *frame)
{
    switch (frame->msg_type)
    {
        case MCPS_MESSAGE:
#if (MAC_INDIRECT_DATA_FFD == 1)
            if (frame->indirect_in_transit)
            {
                // Clear indirect in transmit flag
                frame->indirect_in_transit = false;
                if ((tx_status == MAC_SUCCESS) || (tx_status == TAL_FRAME_PENDING))
                {
                    remove_frame_from_indirect_q(frame);

                    buffer_t *mcps_buf = frame->buffer_header;

                    /* Create the MCPS DATA confirmation message */
                    mac_gen_mcps_data_conf((buffer_t *)mcps_buf,
                                           (uint8_t)tx_status,
#ifdef ENABLE_TSTAMP
                                           frame->msduHandle,
                                           frame->time_stamp);
#else
                                           frame->msduHandle);
#endif  /* ENABLE_TSTAMP */
                }
            }