smplStatus_t nwk_rawReceive(ioctlRawReceive_t *info) { rcvContext_t rcv; rcv.type = RCV_NWK_PORT; rcv.t.port = info->port; return nwk_retrieveFrame(&rcv, info->msg, &info->len, info->addr, &info->hopCount); }
/************************************************************************************** * @fn SMPL_Receive * * @brief Receive a message from a peer application. * * input parameters * @param lid - Link ID (port) from application * * * output parameters * @param msg - pointer to where received message should be copied. * buffer should be of size == MAX_APP_PAYLOAD * @param len - pointer to receive length of received message * * @return Status of operation. * Caller should not use the value returned in 'len' to decide * whether there is a frame or not. It could be useful to the * Caller to distinguish between no frame and a frame with no data. * For example, in the polling case a frame with no application payload * is the way the AP conveys that there are no frames waiting. * * SMPL_SUCCESS * * SMPL_BAD_PARAM No valid Connection Table entry for Link ID * Data in Connection Table entry bad * SMPL_NO_FRAME No frame received. * SMPL_NO_PAYLOAD Frame received with no payload (not necessarily * an error and could be deduced by application * because the returned length will be 0) * * Polling device only: * * SMPL_TIMEOUT No response from Access Point * SMPL_NO_AP_ADDRESS Access Point address unknown * SMPL_TX_CCA_FAIL Could not send poll frame * SMPL_NOMEM No memory in output frame queue * SMPL_NO_CHANNEL Frequency Agility enabled and could not find channel */ smplStatus_t SMPL_Receive(linkID_t lid, uint8_t *msg, uint8_t *len) { connInfo_t *pCInfo = nwk_getConnInfo(lid); smplStatus_t rc = SMPL_BAD_PARAM; rcvContext_t rcv; if (!pCInfo || ((rc=nwk_checkConnInfo(pCInfo, CHK_RX)) != SMPL_SUCCESS)) { return rc; } rcv.type = RCV_APP_LID; rcv.t.lid = lid; #if defined(RX_POLLS) { uint8_t numChans = 1; #if defined(FREQUENCY_AGILITY) freqEntry_t chans[NWK_FREQ_TBL_SIZE]; uint8_t scannedB4 = 0; #endif do { uint8_t radioState = MRFI_GetRadioState(); /* I'm polling. Do the poll to stimulate the sending of a frame. If the * frame has application length of 0 it means there were no frames. If * no reply is received infer that the channel is changed. We then need * to scan and then retry the poll on each channel returned. */ if (SMPL_SUCCESS != (rc=nwk_poll(pCInfo->portRx, pCInfo->peerAddr))) { /* for some reason couldn't send the poll out. */ return rc; } /* do this before code block below which may reset it. */ numChans--; /* Wait until there's a frame. if the len is 0 then return SMPL_NO_FRAME * to the caller. In the poll case the AP always sends something. */ NWK_CHECK_FOR_SETRX(radioState); NWK_REPLY_DELAY(); NWK_CHECK_FOR_RESTORE_STATE(radioState); /* TODO: deal with pending */ rc = nwk_retrieveFrame(&rcv, msg, len, 0, 0); #if defined(FREQUENCY_AGILITY) if (SMPL_SUCCESS == rc) { /* we received something... */ return (*len) ? SMPL_SUCCESS : SMPL_NO_PAYLOAD; } /* No reply. scan for other channel(s) if we haven't already. Then set * one and try again. */ if (!scannedB4) { numChans = nwk_scanForChannels(chans); scannedB4 = 1; } if (numChans) { nwk_setChannel(&chans[numChans-1]); } #else /* FREQUENCY_AGILITY */ return (*len) ? rc : ((SMPL_SUCCESS == rc) ? SMPL_NO_PAYLOAD : SMPL_TIMEOUT); #endif } while (numChans); } #if defined(FREQUENCY_AGILITY) return SMPL_NO_CHANNEL; #endif #else /* RX_POLLS */ return nwk_retrieveFrame(&rcv, msg, len, 0, 0); #endif /* RX_POLLS */ }