} else if (security && security->SecurityLevel) {
status = IEEE154_UNSUPPORTED_SECURITY;
} if ((ScanType > 3) || (ScanType < 3 && ScanDuration > 14) ||
- (ChannelPage != IEEE154_SUPPORTED_CHANNELPAGE) ||
- !(supportedChannels & ScanChannels) ||
- (EnergyDetectListNumEntries && PANDescriptorListNumEntries) ||
+ (ChannelPage != IEEE154_SUPPORTED_CHANNELPAGE) ||
+ !(supportedChannels & ScanChannels) ||
+ ((ScanType != ORPHAN_SCAN) &&
+ ((EnergyDetectListNumEntries && PANDescriptorListNumEntries) ||
(EnergyDetectList != NULL && PANDescriptorList != NULL) ||
(EnergyDetectListNumEntries && EnergyDetectList == NULL) ||
- (PANDescriptorListNumEntries && PANDescriptorList == NULL)) {
+ (PANDescriptorListNumEntries && PANDescriptorList == NULL)))) {
status = IEEE154_INVALID_PARAMETER;
- } else if (ScanType != ENERGY_DETECTION_SCAN &&
- !(m_txFrame = call TxFramePool.get())) {
+ } else if ((ScanType == ACTIVE_SCAN || ScanType == ORPHAN_SCAN) &&
+ ((m_txFrame = call TxFramePool.get()) == NULL)) {
status = IEEE154_TRANSACTION_OVERFLOW;
- } else if (ScanType != ENERGY_DETECTION_SCAN &&
- !(txControl = call TxControlPool.get())) {
+ } else if ((ScanType == ACTIVE_SCAN || ScanType == ORPHAN_SCAN) &&
+ ((txControl = call TxControlPool.get()) == NULL)) {
call TxFramePool.put(m_txFrame);
m_txFrame = NULL;
status = IEEE154_TRANSACTION_OVERFLOW;
} else {
- m_txFrame->header = &txControl->header;
- m_txFrame->payload = m_payload;
- m_txFrame->metadata = &txControl->metadata;
+ if (m_txFrame != NULL){
+ m_txFrame->header = &txControl->header;
+ m_txFrame->payload = m_payload;
+ m_txFrame->metadata = &txControl->metadata;
+ }
m_busy = TRUE;
m_scanType = ScanType;
m_scanChannels = ScanChannels;
uint32_t unscannedChannels = 0;
if (m_terminateScan){
- // scan operation terminated prematurely because the max.
- // number of PAN descriptors/ED samples was reached
- result = IEEE154_LIMIT_REACHED;
-
- // mark the channel on which we received the last beacon
- // as unscanned, because it was not completely scanned
+ // Scan operation terminated because the max.
+ // number of PAN descriptors/ED samples was reached.
+ // Check if there are channels that were unscanned.
+ // In active/passive scan we consider a channel
+ // unscanned if it was not completely scanned.
if (m_scanType == PASSIVE_SCAN || m_scanType == ACTIVE_SCAN)
- currentChannelBit >>= 1;
+ currentChannelBit >>= 1; // last (partially) scanned channel
while (!(currentChannelBit & INVALID_CHANNEL_BITMASK) &&
(m_scanChannels & currentChannelBit)){
unscannedChannels |= currentChannelBit;
currentChannelBit <<= 1;
}
+ if (unscannedChannels) // some channels were not (completely) scanned
+ result = IEEE154_LIMIT_REACHED;
} else if (m_scanType != ENERGY_DETECTION_SCAN && !m_resultIndex)
result = IEEE154_NO_BEACON;
+
if (m_scanType == PASSIVE_SCAN || m_scanType == ACTIVE_SCAN)
call MLME_SET.macPANId(m_PANID);
if (m_txFrame != NULL) {
((uint8_t*) m_resultList)[m_resultIndex++] = EnergyLevel;
if (m_resultIndex == m_resultListNumEntries)
m_terminateScan = TRUE; // done
- call RadioOff.off();
+ if (call RadioOff.off() == EALREADY)
+ signal RadioOff.offDone();
}
/* ----------------------- Active/Orphan scan ----------------------- */