mirror of https://github.com/ARMmbed/mbed-os.git
[IOTCELL-289] Adding Mlme class handle
MAC layer will services will be broken down into independent subsystems. This is the first of those efforts. We have introduced LoRaMacMlme class that handles everything related to MLME subsystem or subservice. To accomodate subsystems we have grouped all protocol level variables into one big data structure. A pointer to that data structure will be passed around the subsystems in order to regulate the entire system. LoRaMac::Send() and LoRaMac::SetTxContWave*() APIs are made public as they are needed to be accessed by the subsystems.pull/6059/head
parent
a3106d2fe6
commit
a100ab0226
File diff suppressed because it is too large
Load Diff
|
|
@ -44,10 +44,9 @@
|
|||
#include "netsocket/LoRaRadio.h"
|
||||
#include "lorastack/phy/LoRaPHY.h"
|
||||
#include "lorawan/system/lorawan_data_structures.h"
|
||||
#include "LoRaMacCommand.h"
|
||||
#include "lorastack/mac/LoRaMacCommand.h"
|
||||
#include "events/EventQueue.h"
|
||||
|
||||
|
||||
#include "lorastack/mac/LoRaMacMlme.h"
|
||||
/*!
|
||||
* Maximum PHY layer payload size
|
||||
*/
|
||||
|
|
@ -332,6 +331,44 @@ public:
|
|||
*/
|
||||
void SetMlmeScheduleUplinkIndication( void );
|
||||
|
||||
/*!
|
||||
* \brief LoRaMAC layer generic send frame
|
||||
*
|
||||
* \param [IN] macHdr MAC header field
|
||||
* \param [IN] fPort MAC payload port
|
||||
* \param [IN] fBuffer MAC data buffer to be sent
|
||||
* \param [IN] fBufferSize MAC data buffer size
|
||||
* \retval status Status of the operation.
|
||||
*/
|
||||
LoRaMacStatus_t Send( LoRaMacHeader_t *macHdr, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
|
||||
|
||||
/*!
|
||||
* \brief Sets the radio in continuous transmission mode
|
||||
*
|
||||
* \remark Uses the radio parameters set on the previous transmission.
|
||||
*
|
||||
* \param [IN] timeout Time in seconds while the radio is kept in continuous wave mode
|
||||
* \retval status Status of the operation.
|
||||
*/
|
||||
LoRaMacStatus_t SetTxContinuousWave( uint16_t timeout );
|
||||
|
||||
/*!
|
||||
* \brief Sets the radio in continuous transmission mode
|
||||
*
|
||||
* \remark Uses the radio parameters set on the previous transmission.
|
||||
*
|
||||
* \param [IN] timeout Time in seconds while the radio is kept in continuous wave mode
|
||||
* \param [IN] frequency RF frequency to be set.
|
||||
* \param [IN] power RF output power to be set.
|
||||
* \retval status Status of the operation.
|
||||
*/
|
||||
LoRaMacStatus_t SetTxContinuousWave1( uint16_t timeout, uint32_t frequency, uint8_t power );
|
||||
|
||||
/*!
|
||||
* \brief Resets MAC specific parameters to default
|
||||
*/
|
||||
void ResetMacParameters( void );
|
||||
|
||||
#if defined(LORAWAN_COMPLIANCE_TEST)
|
||||
public: // Test interface
|
||||
|
||||
|
|
@ -494,17 +531,6 @@ private:
|
|||
*/
|
||||
bool ValidatePayloadLength( uint8_t lenN, int8_t datarate, uint8_t fOptsLen );
|
||||
|
||||
/*!
|
||||
* \brief LoRaMAC layer generic send frame
|
||||
*
|
||||
* \param [IN] macHdr MAC header field
|
||||
* \param [IN] fPort MAC payload port
|
||||
* \param [IN] fBuffer MAC data buffer to be sent
|
||||
* \param [IN] fBufferSize MAC data buffer size
|
||||
* \retval status Status of the operation.
|
||||
*/
|
||||
LoRaMacStatus_t Send( LoRaMacHeader_t *macHdr, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
|
||||
|
||||
/*!
|
||||
* \brief LoRaMAC layer frame buffer initialization
|
||||
*
|
||||
|
|
@ -543,33 +569,6 @@ private:
|
|||
*/
|
||||
LoRaMacStatus_t SendFrameOnChannel( uint8_t channel );
|
||||
|
||||
/*!
|
||||
* \brief Sets the radio in continuous transmission mode
|
||||
*
|
||||
* \remark Uses the radio parameters set on the previous transmission.
|
||||
*
|
||||
* \param [IN] timeout Time in seconds while the radio is kept in continuous wave mode
|
||||
* \retval status Status of the operation.
|
||||
*/
|
||||
LoRaMacStatus_t SetTxContinuousWave( uint16_t timeout );
|
||||
|
||||
/*!
|
||||
* \brief Sets the radio in continuous transmission mode
|
||||
*
|
||||
* \remark Uses the radio parameters set on the previous transmission.
|
||||
*
|
||||
* \param [IN] timeout Time in seconds while the radio is kept in continuous wave mode
|
||||
* \param [IN] frequency RF frequency to be set.
|
||||
* \param [IN] power RF output power to be set.
|
||||
* \retval status Status of the operation.
|
||||
*/
|
||||
LoRaMacStatus_t SetTxContinuousWave1( uint16_t timeout, uint32_t frequency, uint8_t power );
|
||||
|
||||
/*!
|
||||
* \brief Resets MAC specific parameters to default
|
||||
*/
|
||||
void ResetMacParameters( void );
|
||||
|
||||
/*!
|
||||
* \brief Resets MAC specific parameters to default
|
||||
*
|
||||
|
|
@ -609,10 +608,24 @@ private:
|
|||
*/
|
||||
LoRaPHY *lora_phy;
|
||||
|
||||
/**
|
||||
* MAC command handle
|
||||
*/
|
||||
LoRaMacCommand mac_commands;
|
||||
|
||||
/**
|
||||
* MLME subsystem handle
|
||||
*/
|
||||
LoRaMacMlme mlme;
|
||||
|
||||
/**
|
||||
* Timer subsystem handle
|
||||
*/
|
||||
LoRaWANTimeHandler &_lora_time;
|
||||
|
||||
/**
|
||||
* Central MAC layer data storage
|
||||
*/
|
||||
lora_mac_protocol_params _params;
|
||||
|
||||
/**
|
||||
|
|
@ -625,17 +638,6 @@ private:
|
|||
*/
|
||||
MulticastParams_t *MulticastChannels;
|
||||
|
||||
|
||||
/*!
|
||||
* LoRaMac parameters
|
||||
*/
|
||||
LoRaMacParams_t LoRaMacParams;
|
||||
|
||||
/*!
|
||||
* LoRaMac default parameters
|
||||
*/
|
||||
LoRaMacParams_t LoRaMacParamsDefaults;
|
||||
|
||||
/*!
|
||||
* LoRaMac upper layer event functions
|
||||
*/
|
||||
|
|
@ -646,23 +648,6 @@ private:
|
|||
*/
|
||||
LoRaMacCallback_t *LoRaMacCallbacks;
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* LoRaMac reception windows delay
|
||||
* \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
|
||||
* join frame : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
|
||||
*/
|
||||
uint32_t RxWindow1Delay;
|
||||
uint32_t RxWindow2Delay;
|
||||
|
||||
/*!
|
||||
* LoRaMac Rx windows configuration
|
||||
*/
|
||||
RxConfigParams_t RxWindow1Config;
|
||||
RxConfigParams_t RxWindow2Config;
|
||||
|
||||
|
||||
/*!
|
||||
* Structure to hold MCPS indication data.
|
||||
*/
|
||||
|
|
@ -674,19 +659,10 @@ private:
|
|||
McpsConfirm_t McpsConfirm;
|
||||
|
||||
/*!
|
||||
* Structure to hold MLME indication data.
|
||||
* Receive Window configurations for PHY layer
|
||||
*/
|
||||
MlmeIndication_t MlmeIndication;
|
||||
|
||||
/*!
|
||||
* Structure to hold MLME confirm data.
|
||||
*/
|
||||
MlmeConfirm_t MlmeConfirm;
|
||||
|
||||
/*!
|
||||
* Holds the current rx window slot
|
||||
*/
|
||||
LoRaMacRxSlot_t RxSlot;
|
||||
RxConfigParams_t RxWindow1Config;
|
||||
RxConfigParams_t RxWindow2Config;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -252,8 +252,8 @@ bool LoRaMacCommand::IsMacCommandsInNextTx() const
|
|||
}
|
||||
|
||||
void LoRaMacCommand::ProcessMacCommands(uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr,
|
||||
MlmeConfirm_t &MlmeConfirm, LoRaMacCallback_t *LoRaMacCallbacks,
|
||||
LoRaMacParams_t &LoRaMacParams, LoRaPHY &lora_phy)
|
||||
MlmeConfirm_t& MlmeConfirm, LoRaMacCallback_t *LoRaMacCallbacks,
|
||||
lora_mac_system_params_t &LoRaMacParams, LoRaPHY &lora_phy)
|
||||
{
|
||||
uint8_t status = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ public:
|
|||
*/
|
||||
void ProcessMacCommands(uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr,
|
||||
MlmeConfirm_t &MlmeConfirm, LoRaMacCallback_t *LoRaMacCallbacks,
|
||||
LoRaMacParams_t &LoRaMacParams, LoRaPHY &lora_phy);
|
||||
lora_mac_system_params_t &LoRaMacParams, LoRaPHY &lora_phy);
|
||||
|
||||
/*!
|
||||
* \brief Verifies if sticky MAC commands are pending.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
/ _____) _ | |
|
||||
( (____ _____ ____ _| |_ _____ ____| |__
|
||||
\____ \| ___ | (_ _) ___ |/ ___) _ \
|
||||
_____) ) ____| | | || |_| ____( (___| | | |
|
||||
(______/|_____)_|_|_| \__)_____)\____)_| |_|
|
||||
(C)2013 Semtech
|
||||
___ _____ _ ___ _ _____ ___ ___ ___ ___
|
||||
/ __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
|
||||
\__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
|
||||
|___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
|
||||
embedded.connectivity.solutions===============
|
||||
|
||||
Description: LoRaWAN stack layer that controls both MAC and PHY underneath
|
||||
|
||||
License: Revised BSD License, see LICENSE.TXT file include in the project
|
||||
|
||||
Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE )
|
||||
|
||||
|
||||
Copyright (c) 2017, Arm Limited and affiliates.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "LoRaMac.h"
|
||||
#include "lorastack/mac/LoRaMacMlme.h"
|
||||
|
||||
LoRaMacMlme::LoRaMacMlme()
|
||||
: _lora_mac(NULL), _lora_phy(NULL), _mac_cmd(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
LoRaMacMlme::~LoRaMacMlme()
|
||||
{
|
||||
}
|
||||
|
||||
void LoRaMacMlme::activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy,
|
||||
LoRaMacCommand *cmd)
|
||||
{
|
||||
_lora_mac = mac;
|
||||
_lora_phy = phy;
|
||||
_mac_cmd = cmd;
|
||||
}
|
||||
|
||||
LoRaMacStatus_t LoRaMacMlme::set_request(MlmeReq_t *mlmeRequest,
|
||||
lora_mac_protocol_params *params)
|
||||
{
|
||||
if (mlmeRequest && params && _lora_mac && _lora_phy && _mac_cmd) {
|
||||
|
||||
LoRaMacStatus_t status = LORAMAC_STATUS_SERVICE_UNKNOWN;
|
||||
LoRaMacHeader_t macHdr;
|
||||
AlternateDrParams_t altDr;
|
||||
VerifyParams_t verify;
|
||||
GetPhyParams_t getPhy;
|
||||
PhyParam_t phyParam;
|
||||
|
||||
|
||||
if (params->LoRaMacState != LORAMAC_IDLE) {
|
||||
return LORAMAC_STATUS_BUSY;
|
||||
}
|
||||
|
||||
// Before setting a new MLME request, clear the MLME confirmation
|
||||
// structure
|
||||
memset((uint8_t*) &confirmation, 0, sizeof(confirmation));
|
||||
|
||||
confirmation.Status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||
|
||||
switch (mlmeRequest->Type) {
|
||||
case MLME_JOIN: {
|
||||
if ((params->LoRaMacState & LORAMAC_TX_DELAYED)
|
||||
== LORAMAC_TX_DELAYED) {
|
||||
return LORAMAC_STATUS_BUSY;
|
||||
}
|
||||
|
||||
if ((mlmeRequest->Req.Join.DevEui == NULL)
|
||||
|| (mlmeRequest->Req.Join.AppEui == NULL)
|
||||
|| (mlmeRequest->Req.Join.AppKey == NULL)
|
||||
|| (mlmeRequest->Req.Join.NbTrials == 0)) {
|
||||
return LORAMAC_STATUS_PARAMETER_INVALID;
|
||||
}
|
||||
|
||||
// Verify the parameter NbTrials for the join procedure
|
||||
verify.NbJoinTrials = mlmeRequest->Req.Join.NbTrials;
|
||||
|
||||
if (_lora_phy->verify(&verify, PHY_NB_JOIN_TRIALS) == false) {
|
||||
// Value not supported, get default
|
||||
getPhy.Attribute = PHY_DEF_NB_JOIN_TRIALS;
|
||||
phyParam = _lora_phy->get_phy_params(&getPhy);
|
||||
mlmeRequest->Req.Join.NbTrials = (uint8_t) phyParam.Value;
|
||||
}
|
||||
|
||||
params->LoRaMacFlags.Bits.MlmeReq = 1;
|
||||
confirmation.MlmeRequest = mlmeRequest->Type;
|
||||
|
||||
params->keys.LoRaMacDevEui = mlmeRequest->Req.Join.DevEui;
|
||||
params->keys.LoRaMacAppEui = mlmeRequest->Req.Join.AppEui;
|
||||
params->keys.LoRaMacAppKey = mlmeRequest->Req.Join.AppKey;
|
||||
params->MaxJoinRequestTrials = mlmeRequest->Req.Join.NbTrials;
|
||||
|
||||
// Reset variable JoinRequestTrials
|
||||
params->JoinRequestTrials = 0;
|
||||
|
||||
// Setup header information
|
||||
macHdr.Value = 0;
|
||||
macHdr.Bits.MType = FRAME_TYPE_JOIN_REQ;
|
||||
|
||||
_lora_mac->ResetMacParameters();
|
||||
|
||||
altDr.NbTrials = params->JoinRequestTrials + 1;
|
||||
|
||||
params->sys_params.ChannelsDatarate =
|
||||
_lora_phy->get_alternate_DR(&altDr);
|
||||
|
||||
status = _lora_mac->Send(&macHdr, 0, NULL, 0);
|
||||
break;
|
||||
}
|
||||
case MLME_LINK_CHECK: {
|
||||
params->LoRaMacFlags.Bits.MlmeReq = 1;
|
||||
// LoRaMac will send this command piggy-backed
|
||||
confirmation.MlmeRequest = mlmeRequest->Type;
|
||||
|
||||
status = _mac_cmd->AddMacCommand(MOTE_MAC_LINK_CHECK_REQ, 0, 0);
|
||||
break;
|
||||
}
|
||||
case MLME_TXCW: {
|
||||
confirmation.MlmeRequest = mlmeRequest->Type;
|
||||
params->LoRaMacFlags.Bits.MlmeReq = 1;
|
||||
status = _lora_mac->SetTxContinuousWave(mlmeRequest->Req.TxCw.Timeout);
|
||||
break;
|
||||
}
|
||||
case MLME_TXCW_1: {
|
||||
confirmation.MlmeRequest = mlmeRequest->Type;
|
||||
params->LoRaMacFlags.Bits.MlmeReq = 1;
|
||||
status = _lora_mac->SetTxContinuousWave1(mlmeRequest->Req.TxCw.Timeout,
|
||||
mlmeRequest->Req.TxCw.Frequency,
|
||||
mlmeRequest->Req.TxCw.Power);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (status != LORAMAC_STATUS_OK) {
|
||||
params->NodeAckRequested = false;
|
||||
params->LoRaMacFlags.Bits.MlmeReq = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
return LORAMAC_STATUS_PARAMETER_INVALID;
|
||||
}
|
||||
|
||||
MlmeIndication_t& LoRaMacMlme::get_indication()
|
||||
{
|
||||
return indication;
|
||||
}
|
||||
|
||||
MlmeConfirm_t& LoRaMacMlme::get_confirmation()
|
||||
{
|
||||
return confirmation;
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
/ _____) _ | |
|
||||
( (____ _____ ____ _| |_ _____ ____| |__
|
||||
\____ \| ___ | (_ _) ___ |/ ___) _ \
|
||||
_____) ) ____| | | || |_| ____( (___| | | |
|
||||
(______/|_____)_|_|_| \__)_____)\____)_| |_|
|
||||
(C)2013 Semtech
|
||||
___ _____ _ ___ _ _____ ___ ___ ___ ___
|
||||
/ __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
|
||||
\__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
|
||||
|___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
|
||||
embedded.connectivity.solutions===============
|
||||
|
||||
Description: LoRaWAN stack layer that controls both MAC and PHY underneath
|
||||
|
||||
License: Revised BSD License, see LICENSE.TXT file include in the project
|
||||
|
||||
Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE )
|
||||
|
||||
|
||||
Copyright (c) 2017, Arm Limited and affiliates.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef MBED_OS_LORAWAN_MAC_MLME_H_
|
||||
#define MBED_OS_LORAWAN_MAC_MLME_H_
|
||||
|
||||
#include "lorawan/system/lorawan_data_structures.h"
|
||||
#include "lorastack/phy/LoRaPHY.h"
|
||||
#include "lorastack/mac/LoRaMacCommand.h"
|
||||
|
||||
// forward declaration
|
||||
class LoRaMac;
|
||||
|
||||
class LoRaMacMlme {
|
||||
|
||||
public:
|
||||
|
||||
/** Constructor
|
||||
*
|
||||
* Sets local handles to NULL. These handles will be set when the subsystem
|
||||
* is activated by the MAC layer.
|
||||
*/
|
||||
LoRaMacMlme();
|
||||
|
||||
/** Destructor
|
||||
*
|
||||
* Does nothing
|
||||
*/
|
||||
~LoRaMacMlme();
|
||||
|
||||
/** Activating MLME subsystem
|
||||
*
|
||||
* Stores pointers to MAC and PHY layer handles
|
||||
*
|
||||
* @param mac pointer to MAC layer
|
||||
* @param phy pointer to PHY layer
|
||||
* @param cmd pointer to MAC commands
|
||||
*/
|
||||
void activate_mlme_subsystem(LoRaMac *mac, LoRaPHY *phy, LoRaMacCommand *cmd);
|
||||
|
||||
/** Sets up an MLME Request
|
||||
*
|
||||
* Sets up an MLME request, e.g., a Join Request and sends it through
|
||||
* to the central MAC control. It also modifies or uses protocol information
|
||||
* provided in the MAC protocol data structure.
|
||||
*
|
||||
* @param mlmeRequest pointer to MLME request structure
|
||||
* @param params pointer to MAC protocol parameters
|
||||
*
|
||||
* @return LORA_MAC_STATUS_OK if everything goes well otherwise
|
||||
* a negative error code is returned.
|
||||
*/
|
||||
LoRaMacStatus_t set_request(MlmeReq_t *mlmeRequest, lora_mac_protocol_params *params);
|
||||
|
||||
/** Grants access to MLME confirmation data
|
||||
*
|
||||
* @return a reference to MLME confirm data structure
|
||||
*/
|
||||
MlmeConfirm_t& get_confirmation();
|
||||
|
||||
/** Grants access to MLME indication data
|
||||
*
|
||||
* @return a reference to MLME indication data structure
|
||||
*/
|
||||
MlmeIndication_t& get_indication();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Pointers to MAC and PHY handles
|
||||
*/
|
||||
LoRaMac *_lora_mac;
|
||||
LoRaPHY *_lora_phy;
|
||||
LoRaMacCommand *_mac_cmd;
|
||||
|
||||
/**
|
||||
* Structure to hold MLME indication data.
|
||||
*/
|
||||
MlmeIndication_t indication;
|
||||
|
||||
/**
|
||||
* Structure to hold MLME confirm data.
|
||||
*/
|
||||
MlmeConfirm_t confirmation;
|
||||
};
|
||||
|
||||
#endif /* MBED_OS_LORAWAN_MAC_MLME_H_ */
|
||||
|
|
@ -330,7 +330,7 @@ typedef struct sLoRaMacParams
|
|||
* LoRaMac ADR control status
|
||||
*/
|
||||
bool AdrCtrlOn;
|
||||
}LoRaMacParams_t;
|
||||
} lora_mac_system_params_t;
|
||||
|
||||
/*!
|
||||
* LoRaMAC multicast channel parameter.
|
||||
|
|
@ -3044,6 +3044,11 @@ typedef struct {
|
|||
*/
|
||||
DeviceClass_t LoRaMacDeviceClass;
|
||||
|
||||
/*!
|
||||
* Holds the type of current Receive window slot
|
||||
*/
|
||||
LoRaMacRxSlot_t RxSlot;
|
||||
|
||||
/*!
|
||||
* Indicates if the node is connected to a private or public network
|
||||
*/
|
||||
|
|
@ -3200,8 +3205,29 @@ typedef struct {
|
|||
*/
|
||||
uint32_t LoRaMacState;
|
||||
|
||||
/*!
|
||||
* LoRaMac reception windows delay
|
||||
* \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
|
||||
* join frame : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
|
||||
*/
|
||||
uint32_t RxWindow1Delay;
|
||||
uint32_t RxWindow2Delay;
|
||||
|
||||
/*!
|
||||
* Timer objects and stored values
|
||||
*/
|
||||
lora_mac_timers timers;
|
||||
|
||||
/*!
|
||||
* LoRaMac parameters
|
||||
*/
|
||||
lora_mac_system_params_t sys_params;
|
||||
|
||||
/*!
|
||||
* LoRaMac default parameters
|
||||
*/
|
||||
lora_mac_system_params_t def_sys_params;
|
||||
|
||||
} lora_mac_protocol_params;
|
||||
|
||||
/** LoRaWAN callback functions
|
||||
|
|
|
|||
Loading…
Reference in New Issue