Simplified LoRaWAN library.

Fork of LoRaWAN-lib-v1_0_1 by Uttam Bhat

Files at this revision

API Documentation at this revision

Comitter:
dgabino
Date:
Tue Apr 03 17:01:27 2018 +0000
Parent:
11:58f66381eb7c
Commit message:
Substituted api-v3 with MAC layer service

Changed in this revision

LoRaMac-api-v3.cpp Show diff for this revision Revisions of this file
LoRaMac-api-v3.h Show diff for this revision Revisions of this file
LoRaMac-board.h Show annotated file Show diff for this revision Revisions of this file
LoRaMac.cpp Show annotated file Show diff for this revision Revisions of this file
LoRaMac.h Show annotated file Show diff for this revision Revisions of this file
LoRaMacLayerService.cpp Show annotated file Show diff for this revision Revisions of this file
LoRaMacLayerService.h Show annotated file Show diff for this revision Revisions of this file
diff -r 58f66381eb7c -r 54937781831b LoRaMac-api-v3.cpp
--- a/LoRaMac-api-v3.cpp	Fri Nov 10 09:22:15 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,626 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C)2013 Semtech
- ___ _____ _   ___ _  _____ ___  ___  ___ ___
-/ __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
-\__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
-|___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
-embedded.connectivity.solutions===============
-
-Description: LoRa MAC layer implementation
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jäckle ( STACKFORCE )
-*/
-#include "board.h"
-
-#include "LoRaMac-api-v3.h"
-#include "LoRaMacTest.h"
-
-/*!
- *  Extern function declarations.
- */
-extern LoRaMacStatus_t Send( LoRaMacHeader_t *macHdr, uint8_t fPort,
-                             void *fBuffer, uint16_t fBufferSize );
-extern LoRaMacStatus_t PrepareFrame( LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl,
-                                     uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
-extern LoRaMacStatus_t SendFrameOnChannel( ChannelParams_t channel );
-extern uint32_t LoRaMacState;
-extern LoRaMacFlags_t LoRaMacFlags;
-
-/*!
- * Static variables
- */
-static LoRaMacEventFlags_t LoRaMacEventFlags;
-static LoRaMacEventInfo_t LoRaMacEventInfo;
-static LoRaMacPrimitives_t LoRaMacPrimitives;
-static LoRaMacCallback_t LoRaMacCallback;
-static LoRaMacCallbacks_t LoRaMacCallbacks;
-
-/*!
- * \brief   MCPS-Confirm event function
- *
- * \param   [IN] mcpsConfirm - Pointer to the confirm structure,
- *               containing confirm attributes.
- */
-static void McpsConfirm( McpsConfirm_t *mcpsConfirm )
-{
-    LoRaMacEventInfo.Status = mcpsConfirm->Status;
-    LoRaMacEventFlags.Bits.Tx = 1;
-
-    LoRaMacEventInfo.TxDatarate = mcpsConfirm->Datarate;
-    LoRaMacEventInfo.TxNbRetries = mcpsConfirm->NbRetries;
-    LoRaMacEventInfo.TxAckReceived = mcpsConfirm->AckReceived;
-
-    if( ( LoRaMacFlags.Bits.McpsInd != 1 ) && ( LoRaMacFlags.Bits.MlmeReq != 1 ) )
-    {
-        LoRaMacCallbacks.MacEvent( &LoRaMacEventFlags, &LoRaMacEventInfo );
-        LoRaMacEventFlags.Value = 0;
-    }
-}
-
-/*!
- * \brief   MCPS-Indication event function
- *
- * \param   [IN] mcpsIndication - Pointer to the indication structure,
- *               containing indication attributes.
- */
-static void McpsIndication( McpsIndication_t *mcpsIndication )
-{
-    LoRaMacEventInfo.Status = mcpsIndication->Status;
-    LoRaMacEventFlags.Bits.Rx = 1;
-    LoRaMacEventFlags.Bits.RxSlot = mcpsIndication->RxSlot;
-    LoRaMacEventFlags.Bits.Multicast = mcpsIndication->Multicast;
-    if( mcpsIndication->RxData == true )
-    {
-        LoRaMacEventFlags.Bits.RxData = 1;
-    }
-
-    LoRaMacEventInfo.RxPort = mcpsIndication->Port;
-    LoRaMacEventInfo.RxBuffer = mcpsIndication->Buffer;
-    LoRaMacEventInfo.RxBufferSize = mcpsIndication->BufferSize;
-    LoRaMacEventInfo.RxRssi = mcpsIndication->Rssi;
-    LoRaMacEventInfo.RxSnr = mcpsIndication->Snr;
-
-    LoRaMacCallbacks.MacEvent( &LoRaMacEventFlags, &LoRaMacEventInfo );
-    LoRaMacEventFlags.Value = 0;
-}
-
-/*!
- * \brief   MLME-Confirm event function
- *
- * \param   [IN] mlmeConfirm - Pointer to the confirm structure,
- *               containing confirm attributes.
- */
-static void MlmeConfirm( MlmeConfirm_t *mlmeConfirm )
-{
-    if( mlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
-    {
-        switch( mlmeConfirm->MlmeRequest )
-        {
-            case MLME_JOIN:
-            {
-                // Status is OK, node has joined the network
-                LoRaMacEventFlags.Bits.Tx = 1;
-                LoRaMacEventFlags.Bits.Rx = 1;
-                LoRaMacEventFlags.Bits.JoinAccept = 1;
-                break;
-            }
-            case MLME_LINK_CHECK:
-            {
-                LoRaMacEventFlags.Bits.Tx = 1;
-                LoRaMacEventFlags.Bits.Rx = 1;
-                LoRaMacEventFlags.Bits.LinkCheck = 1;
-
-                LoRaMacEventInfo.DemodMargin = mlmeConfirm->DemodMargin;
-                LoRaMacEventInfo.NbGateways = mlmeConfirm->NbGateways;
-                break;
-            }
-            default:
-                break;
-        }
-    }
-    LoRaMacEventInfo.Status = mlmeConfirm->Status;
-
-    if( LoRaMacFlags.Bits.McpsInd != 1 )
-    {
-        LoRaMacCallbacks.MacEvent( &LoRaMacEventFlags, &LoRaMacEventInfo );
-        LoRaMacEventFlags.Value = 0;
-    }
-}
-
-void LoRaMacInit( LoRaMacCallbacks_t *callbacks )
-{
-    LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
-    LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
-    LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
-
-    LoRaMacCallbacks.MacEvent = callbacks->MacEvent;
-    LoRaMacCallbacks.GetBatteryLevel = callbacks->GetBatteryLevel;
-    LoRaMacCallback.GetBatteryLevel = callbacks->GetBatteryLevel;
-
-    LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallback );
-}
-
-void LoRaMacSetAdrOn( bool enable )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_ADR;
-    mibSet.Param.AdrEnable = enable;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacInitNwkIds( uint32_t netID, uint32_t devAddr, uint8_t *nwkSKey, uint8_t *appSKey )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_NET_ID;
-    mibSet.Param.NetID = netID;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-
-    mibSet.Type = MIB_DEV_ADDR;
-    mibSet.Param.DevAddr = devAddr;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-
-    mibSet.Type = MIB_NWK_SKEY;
-    mibSet.Param.NwkSKey = nwkSKey;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-
-    mibSet.Type = MIB_APP_SKEY;
-    mibSet.Param.AppSKey = appSKey;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-
-    mibSet.Type = MIB_NETWORK_JOINED;
-    mibSet.Param.IsNetworkJoined = true;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacMulticastChannelAdd( MulticastParams_t *channelParam )
-{
-    LoRaMacMulticastChannelLink( channelParam );
-}
-
-void LoRaMacMulticastChannelRemove( MulticastParams_t *channelParam )
-{
-    LoRaMacMulticastChannelUnlink( channelParam );
-}
-
-uint8_t LoRaMacJoinReq( uint8_t *devEui, uint8_t *appEui, uint8_t *appKey )
-{
-    MlmeReq_t mlmeRequest;
-    uint8_t status;
-
-    mlmeRequest.Type = MLME_JOIN;
-    mlmeRequest.Req.Join.AppEui = appEui;
-    mlmeRequest.Req.Join.AppKey = appKey;
-    mlmeRequest.Req.Join.DevEui = devEui;
-
-    switch( LoRaMacMlmeRequest( &mlmeRequest ) )
-    {
-        case LORAMAC_STATUS_OK:
-        {
-            status = 0;
-            break;
-        }
-        case LORAMAC_STATUS_BUSY:
-        {
-            status = 1;
-            break;
-        }
-        case LORAMAC_STATUS_NO_NETWORK_JOINED:
-        {
-            status = 2;
-            break;
-        }
-        case LORAMAC_STATUS_LENGTH_ERROR:
-        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
-        {
-            status = 3;
-            break;
-        }
-        case LORAMAC_STATUS_SERVICE_UNKNOWN:
-        {
-            status = 4;
-            break;
-        }
-        case LORAMAC_STATUS_DEVICE_OFF:
-        {
-            status = 6;
-            break;
-        }
-        default:
-        {
-            status = 1;
-            break;
-        }
-    }
-
-    return status;
-}
-
-uint8_t LoRaMacLinkCheckReq( void )
-{
-    MlmeReq_t mlmeRequest;
-    uint8_t status;
-
-    mlmeRequest.Type = MLME_LINK_CHECK;
-
-    switch( LoRaMacMlmeRequest( &mlmeRequest ) )
-    {
-        case LORAMAC_STATUS_OK:
-        {
-            status = 0;
-            break;
-        }
-        case LORAMAC_STATUS_SERVICE_UNKNOWN:
-        {
-            status = 1;
-            break;
-        }
-        default:
-        {
-            status = 1;
-            break;
-        }
-    }
-
-    return status;
-}
-
-uint8_t LoRaMacSendFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
-{
-    MibRequestConfirm_t mibGet;
-    McpsReq_t mcpsRequest;
-    uint8_t retStatus;
-
-    memset1( ( uint8_t* )&LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) );
-
-    mibGet.Type = MIB_CHANNELS_DATARATE;
-    LoRaMacMibGetRequestConfirm( &mibGet );
-
-    mcpsRequest.Type = MCPS_UNCONFIRMED;
-    mcpsRequest.Req.Unconfirmed.fBuffer = fBuffer;
-    mcpsRequest.Req.Unconfirmed.fBufferSize = fBufferSize;
-    mcpsRequest.Req.Unconfirmed.fPort = fPort;
-    mcpsRequest.Req.Unconfirmed.Datarate = mibGet.Param.ChannelsDatarate;
-
-    switch( LoRaMacMcpsRequest( &mcpsRequest ) )
-    {
-        case LORAMAC_STATUS_OK:
-            retStatus = 0U;
-            break;
-        case LORAMAC_STATUS_BUSY:
-            retStatus = 1U;
-            break;
-        case LORAMAC_STATUS_NO_NETWORK_JOINED:
-            retStatus = 2U;
-            break;
-        case LORAMAC_STATUS_LENGTH_ERROR:
-        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
-            retStatus = 3U;
-            break;
-        case LORAMAC_STATUS_SERVICE_UNKNOWN:
-            retStatus = 4U;
-            break;
-        case LORAMAC_STATUS_DEVICE_OFF:
-            retStatus = 6U;
-            break;
-        default:
-            retStatus = 1U;
-            break;
-    }
-
-    return retStatus;
-}
-
-uint8_t LoRaMacSendConfirmedFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize, uint8_t nbRetries )
-{
-    MibRequestConfirm_t mibGet;
-    McpsReq_t mcpsRequest;
-    uint8_t retStatus;
-
-    memset1( ( uint8_t* )&LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) );
-
-    mibGet.Type = MIB_CHANNELS_DATARATE;
-    LoRaMacMibGetRequestConfirm( &mibGet );
-
-    mcpsRequest.Type = MCPS_CONFIRMED;
-    mcpsRequest.Req.Confirmed.fBuffer = fBuffer;
-    mcpsRequest.Req.Confirmed.fBufferSize = fBufferSize;
-    mcpsRequest.Req.Confirmed.fPort = fPort;
-    mcpsRequest.Req.Confirmed.NbTrials = nbRetries;
-    mcpsRequest.Req.Confirmed.Datarate = mibGet.Param.ChannelsDatarate;
-
-    switch( LoRaMacMcpsRequest( &mcpsRequest ) )
-    {
-        case LORAMAC_STATUS_OK:
-            retStatus = 0U;
-            break;
-        case LORAMAC_STATUS_BUSY:
-            retStatus = 1U;
-            break;
-        case LORAMAC_STATUS_NO_NETWORK_JOINED:
-            retStatus = 2U;
-            break;
-        case LORAMAC_STATUS_LENGTH_ERROR:
-        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
-            retStatus = 3U;
-            break;
-        case LORAMAC_STATUS_SERVICE_UNKNOWN:
-            retStatus = 4U;
-            break;
-        case LORAMAC_STATUS_DEVICE_OFF:
-            retStatus = 6U;
-            break;
-        default:
-            retStatus = 1U;
-            break;
-    }
-
-    return retStatus;
-}
-
-uint8_t LoRaMacSend( LoRaMacHeader_t *macHdr, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
-{
-    uint8_t retStatus;
-
-    memset1( ( uint8_t* ) &LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) );
-
-    switch( Send( macHdr, fPort, fBuffer, fBufferSize ) )
-    {
-        case LORAMAC_STATUS_OK:
-            retStatus = 0U;
-            break;
-        case LORAMAC_STATUS_BUSY:
-            retStatus = 1U;
-            break;
-        case LORAMAC_STATUS_NO_NETWORK_JOINED:
-            retStatus = 2U;
-            break;
-        case LORAMAC_STATUS_LENGTH_ERROR:
-        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
-            retStatus = 3U;
-            break;
-        case LORAMAC_STATUS_SERVICE_UNKNOWN:
-            retStatus = 4U;
-            break;
-        case LORAMAC_STATUS_DEVICE_OFF:
-            retStatus = 6U;
-            break;
-        default:
-            retStatus = 1U;
-            break;
-    }
-
-    return retStatus;
-}
-
-uint8_t LoRaMacPrepareFrame( ChannelParams_t channel,LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
-{
-    uint8_t retStatus;
-
-    switch( PrepareFrame( macHdr, fCtrl, fPort, fBuffer, fBufferSize ) )
-    {
-        case LORAMAC_STATUS_OK:
-            retStatus = 0U;
-            break;
-        case LORAMAC_STATUS_BUSY:
-            retStatus = 1U;
-            break;
-        case LORAMAC_STATUS_NO_NETWORK_JOINED:
-            retStatus = 2U;
-            break;
-        case LORAMAC_STATUS_LENGTH_ERROR:
-        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
-            retStatus = 3U;
-            break;
-        case LORAMAC_STATUS_SERVICE_UNKNOWN:
-            retStatus = 4U;
-            break;
-        default:
-            retStatus = 1U;
-            break;
-    }
-
-    return retStatus;
-}
-
-uint8_t LoRaMacSendFrameOnChannel( ChannelParams_t channel )
-{
-    memset1( ( uint8_t* ) &LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) );
-
-    SendFrameOnChannel( channel );
-
-    /* SendFrameOnChannel has always status "OK" */
-    return 0;
-}
-
-uint8_t LoRaMacSendOnChannel( ChannelParams_t channel, LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize )
-{
-    uint8_t status = 0;
-
-    if( ( LoRaMacState & 0x00000001 ) == 0x00000001 )
-    {
-        return 1; // MAC is busy transmitting a previous frame
-    }
-
-    status = LoRaMacPrepareFrame( channel, macHdr, fCtrl, fOpts, fPort, fBuffer, fBufferSize );
-    if( status != 0 )
-    {
-        return status;
-    }
-
-    LoRaMacEventInfo.TxNbRetries = 0;
-    LoRaMacEventInfo.TxAckReceived = false;
-
-    return LoRaMacSendFrameOnChannel( channel );
-}
-
-void LoRaMacSetDeviceClass( DeviceClass_t deviceClass )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_DEVICE_CLASS;
-    mibSet.Param.Class = deviceClass;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetPublicNetwork( bool enable )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_PUBLIC_NETWORK;
-    mibSet.Param.EnablePublicNetwork = enable;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetDutyCycleOn( bool enable )
-{
-    LoRaMacTestSetDutyCycleOn( enable );
-}
-
-void LoRaMacSetChannel( uint8_t id, ChannelParams_t params )
-{
-    LoRaMacChannelAdd( id, params );
-}
-
-void LoRaMacSetRx2Channel( Rx2ChannelParams_t param )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_RX2_CHANNEL;
-    mibSet.Param.Rx2Channel = param;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetChannelsMask( uint16_t *mask )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_CHANNELS_MASK;
-    mibSet.Param.ChannelsMask = mask;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetChannelsNbRep( uint8_t nbRep )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_CHANNELS_NB_REP;
-    mibSet.Param.ChannelNbRep = nbRep;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetMaxRxWindow( uint32_t delay )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_MAX_RX_WINDOW_DURATION;
-    mibSet.Param.MaxRxWindow = delay;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetReceiveDelay1( uint32_t delay )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_RECEIVE_DELAY_1;
-    mibSet.Param.ReceiveDelay1 = delay;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetReceiveDelay2( uint32_t delay )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_RECEIVE_DELAY_2;
-    mibSet.Param.ReceiveDelay2 = delay;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetJoinAcceptDelay1( uint32_t delay )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_JOIN_ACCEPT_DELAY_1;
-    mibSet.Param.JoinAcceptDelay1 = delay;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetJoinAcceptDelay2( uint32_t delay )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_JOIN_ACCEPT_DELAY_2;
-    mibSet.Param.JoinAcceptDelay2 = delay;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetChannelsDatarate( int8_t datarate )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_CHANNELS_DATARATE;
-    mibSet.Param.ChannelsDatarate = datarate;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-void LoRaMacSetChannelsTxPower( int8_t txPower )
-{
-    MibRequestConfirm_t mibSet;
-
-    mibSet.Type = MIB_CHANNELS_TX_POWER;
-    mibSet.Param.ChannelsTxPower = txPower;
-
-    LoRaMacMibSetRequestConfirm( &mibSet );
-}
-
-uint32_t LoRaMacGetUpLinkCounter( void )
-{
-    MibRequestConfirm_t mibGet;
-
-    mibGet.Type = MIB_UPLINK_COUNTER;
-
-    LoRaMacMibGetRequestConfirm( &mibGet );
-
-    return mibGet.Param.UpLinkCounter;
-}
-
-uint32_t LoRaMacGetDownLinkCounter( void )
-{
-    MibRequestConfirm_t mibGet;
-
-    mibGet.Type = MIB_DOWNLINK_COUNTER;
-
-    LoRaMacMibGetRequestConfirm( &mibGet );
-
-    return mibGet.Param.DownLinkCounter;
-}
-
-void LoRaMacSetMicTest( uint16_t txPacketCounter )
-{
-    LoRaMacTestSetMic( txPacketCounter );
-}
diff -r 58f66381eb7c -r 54937781831b LoRaMac-api-v3.h
--- a/LoRaMac-api-v3.h	Fri Nov 10 09:22:15 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,475 +0,0 @@
-/*!
- * \file      LoRaMac-api-v3.h
- *
- * \brief     LoRa MAC wrapper layer implementation
- *
- * \copyright Revised BSD License, see section \ref LICENSE.
- *
- * \code
- *                ______                              _
- *               / _____)             _              | |
- *              ( (____  _____ ____ _| |_ _____  ____| |__
- *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- *               _____) ) ____| | | || |_| ____( (___| | | |
- *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
- *              (C)2013 Semtech
- *
- *               ___ _____ _   ___ _  _____ ___  ___  ___ ___
- *              / __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
- *              \__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
- *              |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
- *              embedded.connectivity.solutions===============
- *
- * \endcode
- *
- * \author    Miguel Luis ( Semtech )
- *
- * \author    Gregory Cristian ( Semtech )
- *
- * \author    Daniel Jäckle ( STACKFORCE )
- */
-#ifndef __LORAMAC_API_V3_H__
-#define __LORAMAC_API_V3_H__
-
-// Includes board dependent definitions such as channels frequencies
-#include "LoRaMac.h"
-#include "LoRaMac-board.h"
-
-/*!
- * Beacon interval in us
- */
-#define BEACON_INTERVAL                             128000000
-
-/*!
- * Class A&B receive delay 1 in us
- */
-#define RECEIVE_DELAY1                              1000000
-
-/*!
- * Class A&B receive delay 2 in us
- */
-#define RECEIVE_DELAY2                              2000000
-
-/*!
- * Join accept receive delay 1 in us
- */
-#define JOIN_ACCEPT_DELAY1                          5000000
-
-/*!
- * Join accept receive delay 2 in us
- */
-#define JOIN_ACCEPT_DELAY2                          6000000
-
-/*!
- * Class A&B maximum receive window delay in us
- */
-#define MAX_RX_WINDOW                               3000000
-
-/*!
- * Maximum allowed gap for the FCNT field
- */
-#define MAX_FCNT_GAP                                16384
-
-/*!
- * ADR acknowledgement counter limit
- */
-#define ADR_ACK_LIMIT                               64
-
-/*!
- * Number of ADR acknowledgement requests before returning to default datarate
- */
-#define ADR_ACK_DELAY                               32
-
-/*!
- * Number of seconds after the start of the second reception window without
- * receiving an acknowledge.
- * AckTimeout = \ref ACK_TIMEOUT + Random( -\ref ACK_TIMEOUT_RND, \ref ACK_TIMEOUT_RND )
- */
-#define ACK_TIMEOUT                                 2000000
-
-/*!
- * Random number of seconds after the start of the second reception window without
- * receiving an acknowledge
- * AckTimeout = \ref ACK_TIMEOUT + Random( -\ref ACK_TIMEOUT_RND, \ref ACK_TIMEOUT_RND )
- */
-#define ACK_TIMEOUT_RND                             1000000
-
-/*!
- * Check the Mac layer state every MAC_STATE_CHECK_TIMEOUT in us
- */
-#define MAC_STATE_CHECK_TIMEOUT                     1000000
-
-/*!
- * Maximum number of times the MAC layer tries to get an acknowledge.
- */
-#define MAX_ACK_RETRIES                             8
-
-/*!
- * RSSI free threshold [dBm]
- */
-#define RSSI_FREE_TH                                ( int8_t )( -90 )
-
-/*!
- * Frame direction definition for up-link communications
- */
-#define UP_LINK                                     0
-
-/*!
- * Frame direction definition for down-link communications
- */
-#define DOWN_LINK                                   1
-
-/*!
- * Sets the length of the LoRaMAC footer field.
- * Mainly indicates the MIC field length
- */
-#define LORAMAC_MFR_LEN                             4
-
-/*!
- * Syncword for Private LoRa networks
- */
-#define LORA_MAC_PRIVATE_SYNCWORD                   0x12
-
-/*!
- * Syncword for Public LoRa networks
- */
-#define LORA_MAC_PUBLIC_SYNCWORD                    0x34
-
-/*!
- * LoRaMAC event flags
- */
-typedef union
-{
-    uint8_t Value;
-    struct
-    {
-        uint8_t Tx              : 1;
-        uint8_t Rx              : 1;
-        uint8_t RxData          : 1;
-        uint8_t Multicast       : 1;
-        uint8_t RxSlot          : 2;
-        uint8_t LinkCheck       : 1;
-        uint8_t JoinAccept      : 1;
-    }Bits;
-}LoRaMacEventFlags_t;
-
-/*!
- * LoRaMAC event information
- */
-typedef struct
-{
-    LoRaMacEventInfoStatus_t Status;
-    bool TxAckReceived;
-    uint8_t TxNbRetries;
-    uint8_t TxDatarate;
-    uint8_t RxPort;
-    uint8_t *RxBuffer;
-    uint8_t RxBufferSize;
-    int16_t RxRssi;
-    uint8_t RxSnr;
-    uint16_t Energy;
-    uint8_t DemodMargin;
-    uint8_t NbGateways;
-}LoRaMacEventInfo_t;
-
-/*!
- * LoRaMAC events structure
- * Used to notify upper layers of MAC events
- */
-typedef struct sLoRaMacCallbacks
-{
-    /*!
-     * MAC layer event callback prototype.
-     *
-     * \param [IN] flags Bit field indicating the MAC events occurred
-     * \param [IN] info  Details about MAC events occurred
-     */
-    void ( *MacEvent )( LoRaMacEventFlags_t *flags, LoRaMacEventInfo_t *info );
-    /*!
-     * Function callback to get the current battery level
-     *
-     * \retval batteryLevel Current battery level
-     */
-    uint8_t ( *GetBatteryLevel )( void );
-}LoRaMacCallbacks_t;
-
-/*!
- * LoRaMAC layer initialization
- *
- * \param [IN] callbacks     Pointer to a structure defining the LoRaMAC
- *                           callback functions.
- */
-void LoRaMacInit( LoRaMacCallbacks_t *callbacks );
-
-/*!
- * Enables/Disables the ADR (Adaptive Data Rate)
- *
- * \param [IN] enable [true: ADR ON, false: ADR OFF]
- */
-void LoRaMacSetAdrOn( bool enable );
-
-/*!
- * Initializes the network IDs. Device address,
- * network session AES128 key and application session AES128 key.
- *
- * \remark To be only used when Over-the-Air activation isn't used.
- *
- * \param [IN] netID   24 bits network identifier
- *                     ( provided by network operator )
- * \param [IN] devAddr 32 bits device address on the network
- *                     (must be unique to the network)
- * \param [IN] nwkSKey Pointer to the network session AES128 key array
- *                     ( 16 bytes )
- * \param [IN] appSKey Pointer to the application session AES128 key array
- *                     ( 16 bytes )
- */
-void LoRaMacInitNwkIds( uint32_t netID, uint32_t devAddr, uint8_t *nwkSKey, uint8_t *appSKey );
-
-/*
- * Wrapper function which calls \ref LoRaMacMulticastChannelLink.
- */
-void LoRaMacMulticastChannelAdd( MulticastParams_t *channelParam );
-
-/*
- * Wrapper function which calls \ref LoRaMacMulticastChannelUnlink.
- */
-void LoRaMacMulticastChannelRemove( MulticastParams_t *channelParam );
-
-/*!
- * Initiates the Over-the-Air activation
- *
- * \param [IN] devEui Pointer to the device EUI array ( 8 bytes )
- * \param [IN] appEui Pointer to the application EUI array ( 8 bytes )
- * \param [IN] appKey Pointer to the application AES128 key array ( 16 bytes )
- *
- * \retval status [0: OK, 1: Tx error, 2: Already joined a network]
- */
-uint8_t LoRaMacJoinReq( uint8_t *devEui, uint8_t *appEui, uint8_t *appKey );
-
-/*!
- * Sends a LinkCheckReq MAC command on the next uplink frame
- *
- * \retval status Function status [0: OK, 1: Busy]
- */
-uint8_t LoRaMacLinkCheckReq( void );
-
-/*!
- * LoRaMAC layer send frame
- *
- * \param [IN] fPort       MAC payload port (must be > 0)
- * \param [IN] fBuffer     MAC data buffer to be sent
- * \param [IN] fBufferSize MAC data buffer size
- *
- * \retval status          [0: OK, 1: Busy, 2: No network joined,
- *                          3: Length or port error, 4: Unknown MAC command
- *                          5: Unable to find a free channel
- *                          6: Device switched off]
- */
-uint8_t LoRaMacSendFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
-
-/*!
- * LoRaMAC layer send frame
- *
- * \param [IN] fPort       MAC payload port (must be > 0)
- * \param [IN] fBuffer     MAC data buffer to be sent
- * \param [IN] fBufferSize MAC data buffer size
- * \param [IN] fBufferSize MAC data buffer size
- * \param [IN] nbRetries   Number of retries to receive the acknowledgement
- *
- * \retval status          [0: OK, 1: Busy, 2: No network joined,
- *                          3: Length or port error, 4: Unknown MAC command
- *                          5: Unable to find a free channel
- *                          6: Device switched off]
- */
-uint8_t LoRaMacSendConfirmedFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize, uint8_t nbRetries );
-
-/*!
- * ============================================================================
- * = LoRaMac test functions                                                   =
- * ============================================================================
- */
-
-/*!
- * LoRaMAC layer generic send frame
- *
- * \param [IN] macHdr      MAC header field
- * \param [IN] fOpts       MAC commands buffer
- * \param [IN] fPort       MAC payload port
- * \param [IN] fBuffer     MAC data buffer to be sent
- * \param [IN] fBufferSize MAC data buffer size
- * \retval status          [0: OK, 1: Busy, 2: No network joined,
- *                          3: Length or port error, 4: Unknown MAC command
- *                          5: Unable to find a free channel
- *                          6: Device switched off]
- */
-uint8_t LoRaMacSend( LoRaMacHeader_t *macHdr, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
-
-/*!
- * LoRaMAC layer frame buffer initialization.
- *
- * \param [IN] channel     Channel parameters
- * \param [IN] macHdr      MAC header field
- * \param [IN] fCtrl       MAC frame control field
- * \param [IN] fOpts       MAC commands buffer
- * \param [IN] fPort       MAC payload port
- * \param [IN] fBuffer     MAC data buffer to be sent
- * \param [IN] fBufferSize MAC data buffer size
- * \retval status          [0: OK, 1: N/A, 2: No network joined,
- *                          3: Length or port error, 4: Unknown MAC command]
- */
-uint8_t LoRaMacPrepareFrame( ChannelParams_t channel,LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
-
-/*!
- * LoRaMAC layer prepared frame buffer transmission with channel specification
- *
- * \remark LoRaMacPrepareFrame must be called at least once before calling this
- *         function.
- *
- * \param [IN] channel     Channel parameters
- * \retval status          [0: OK, 1: Busy]
- */
-uint8_t LoRaMacSendFrameOnChannel( ChannelParams_t channel );
-
-/*!
- * LoRaMAC layer generic send frame with channel specification
- *
- * \param [IN] channel     Channel parameters
- * \param [IN] macHdr      MAC header field
- * \param [IN] fCtrl       MAC frame control field
- * \param [IN] fOpts       MAC commands buffer
- * \param [IN] fPort       MAC payload port
- * \param [IN] fBuffer     MAC data buffer to be sent
- * \param [IN] fBufferSize MAC data buffer size
- * \retval status          [0: OK, 1: Busy, 2: No network joined,
- *                          3: Length or port error, 4: Unknown MAC command]
- */
-uint8_t LoRaMacSendOnChannel( ChannelParams_t channel, LoRaMacHeader_t *macHdr, LoRaMacFrameCtrl_t *fCtrl, uint8_t *fOpts, uint8_t fPort, void *fBuffer, uint16_t fBufferSize );
-
-/*!
- * ============================================================================
- * = LoRaMac setup functions                                                  =
- * ============================================================================
- */
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the LoRaWan device class.
- */
-void LoRaMacSetDeviceClass( DeviceClass_t deviceClass );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the network type to public or private.
- */
-void LoRaMacSetPublicNetwork( bool enable );
-
-/*
- * Wrapper function which calls \ref LoRaMacChannelAdd.
- */
-void LoRaMacSetChannel( uint8_t id, ChannelParams_t params );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the receive window 2 channel.
- */
-void LoRaMacSetRx2Channel( Rx2ChannelParams_t param );
-
-/*!
- * Sets channels tx output power
- *
- * \param [IN] txPower [TX_POWER_20_DBM, TX_POWER_14_DBM,
-                        TX_POWER_11_DBM, TX_POWER_08_DBM,
-                        TX_POWER_05_DBM, TX_POWER_02_DBM]
- */
-void LoRaMacSetChannelsTxPower( int8_t txPower );
-
-/*!
- * Sets channels datarate
- *
- * \param [IN] datarate eu868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7]
- *                      us915 - [DR_0, DR_1, DR_2, DR_3, DR_4]
- */
-void LoRaMacSetChannelsDatarate( int8_t datarate );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the channels mask.
- */
-void LoRaMacSetChannelsMask( uint16_t *mask );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the number of repetitions on a channel.
- */
-void LoRaMacSetChannelsNbRep( uint8_t nbRep );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the maximum receive window duration in [us].
- */
-void LoRaMacSetMaxRxWindow( uint32_t delay );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the receive delay 1 in [us].
- */
-void LoRaMacSetReceiveDelay1( uint32_t delay );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the receive delay 2 in [us].
- */
-void LoRaMacSetReceiveDelay2( uint32_t delay );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the join accept delay 1 in [us].
- */
-void LoRaMacSetJoinAcceptDelay1( uint32_t delay );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibSetRequestConfirm to
- * set the join accept delay 2 in [us].
- */
-void LoRaMacSetJoinAcceptDelay2( uint32_t delay );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibGetRequestConfirm to
- * get the up-link counter.
- */
-uint32_t LoRaMacGetUpLinkCounter( void );
-
-/*
- * Wrapper function which calls \ref LoRaMacMibGetRequestConfirm to
- * get the down-link counter.
- */
-uint32_t LoRaMacGetDownLinkCounter( void );
-
-/*
- * ============================================================================
- * = LoRaMac test functions                                                   =
- * ============================================================================
- */
-
-/*!
- * Disables/Enables the duty cycle enforcement (EU868)
- *
- * \param   [IN] enable - Enabled or disables the duty cycle
- */
-void LoRaMacTestSetDutyCycleOn( bool enable );
-
-/*!
- * Disables/Enables the reception windows opening
- *
- * \param [IN] enable [true: enable, false: disable]
- */
-void LoRaMacTestRxWindowsOn( bool enable );
-
-/*!
- * Enables the MIC field test
- *
- * \param [IN] upLinkCounter Fixed Tx packet counter value
- */
-void LoRaMacTestSetMic( uint16_t upLinkCounter );
-
-#endif /* __LORAMAC_API_V3_H__ */
diff -r 58f66381eb7c -r 54937781831b LoRaMac-board.h
--- a/LoRaMac-board.h	Fri Nov 10 09:22:15 2017 +0000
+++ b/LoRaMac-board.h	Tue Apr 03 17:01:27 2018 +0000
@@ -420,7 +420,7 @@
 #define LORAMAC_MIN_TX_POWER                        TX_POWER_10_DBM
 
 /*!
- * Minimal Tx output power that can be used by the node
+ * Maximum Tx output power that can be used by the node
  */
 #define LORAMAC_MAX_TX_POWER                        TX_POWER_30_DBM
 
diff -r 58f66381eb7c -r 54937781831b LoRaMac.cpp
--- a/LoRaMac.cpp	Fri Nov 10 09:22:15 2017 +0000
+++ b/LoRaMac.cpp	Tue Apr 03 17:01:27 2018 +0000
@@ -2873,13 +2873,13 @@
     ChannelsMask[3] = 0x0000;
     ChannelsMask[4] = 0x0001;
     ChannelsMask[5] = 0x0000;
-
-    memcpy1( ( uint8_t* ) ChannelsMaskRemaining, ( uint8_t* ) ChannelsMask, sizeof( ChannelsMask ) );
+    
+    memcpy1( ( uint8_t* ) ChannelsMaskRemaining, ( uint8_t* ) ChannelsMask, sizeof( ChannelsMask ) );   //save channel mask in memory
 #else
     #error "Please define a frequency band in the compiler options."
 #endif
 
-#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )
+#if defined( USE_BAND_915 ) || defined( USE_BAND_915_HYBRID )   //set frequency for channels
     // 125 kHz channels
     for( uint8_t i = 0; i < LORA_MAX_NB_CHANNELS - 8; i++ )
     {
@@ -2887,7 +2887,7 @@
         Channels[i].DrRange.Value = ( DR_3 << 4 ) | DR_0;
         Channels[i].Band = 0;
     }
-    // 500 kHz channels
+    // 500 kHz channels1
     for( uint8_t i = LORA_MAX_NB_CHANNELS - 8; i < LORA_MAX_NB_CHANNELS; i++ )
     {
         Channels[i].Frequency = 903.0e6 + ( i - ( LORA_MAX_NB_CHANNELS - 8 ) ) * 1.6e6;
diff -r 58f66381eb7c -r 54937781831b LoRaMac.h
--- a/LoRaMac.h	Fri Nov 10 09:22:15 2017 +0000
+++ b/LoRaMac.h	Tue Apr 03 17:01:27 2018 +0000
@@ -116,7 +116,7 @@
 /*!
  * Maximum number of times the MAC layer tries to get an acknowledge.
  */
-#define MAX_ACK_RETRIES                             8
+#define MAX_ACK_RETRIES                             4
 
 /*!
  * RSSI free threshold [dBm]
@@ -760,38 +760,22 @@
  */
 typedef struct sMcpsConfirm
 {
-    /*!
-     * Holds the previously performed MCPS-Request
-     */
-    Mcps_t McpsRequest;
-    /*!
-     * Status of the operation
-     */
-    LoRaMacEventInfoStatus_t Status;
-    /*!
-     * Uplink datarate
-     */
-    uint8_t Datarate;
-    /*!
-     * Transmission power
-     */
-    int8_t TxPower;
-    /*!
-     * Set if an acknowledgement was received
-     */
-    bool AckReceived;
-    /*!
-     * Provides the number of retransmissions
-     */
-    uint8_t NbRetries;
-    /*!
-     * The transmission time on air of the frame
-     */
-    TimerTime_t TxTimeOnAir;
-    /*!
-     * The uplink counter value related to the frame
-     */
-    uint32_t UpLinkCounter;
+    
+    Mcps_t McpsRequest;     //Holds the previously performed MCPS-Request
+    
+    LoRaMacEventInfoStatus_t Status;       //Status of the operation
+    
+    uint8_t Datarate;       //Uplink datarate
+    
+    int8_t TxPower;     //Transmission power
+    
+    bool AckReceived;       //Set if an acknowledgement was received
+    
+    uint8_t NbRetries;      // Provides the number of retransmissions
+    
+    TimerTime_t TxTimeOnAir;        //The transmission time on air of the frame
+    
+    uint32_t UpLinkCounter;     //The uplink counter value related to the frame
 }McpsConfirm_t;
 
 /*!
diff -r 58f66381eb7c -r 54937781831b LoRaMacLayerService.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRaMacLayerService.cpp	Tue Apr 03 17:01:27 2018 +0000
@@ -0,0 +1,146 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2015 Semtech
+
+Description: MAC Layer Services: MLME & MCPS
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Uttam Bhat
+*/
+
+#include "LoRaMacLayerService.h"
+
+/*!
+ * \brief   MCPS-Confirm event function
+ *
+ * \param   [IN] McpsConfirm - Pointer to the confirm structure,
+ *               containing confirm attributes.
+ */
+void McpsConfirm( McpsConfirm_t *McpsConfirm )
+{
+    if( McpsConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
+    {
+        if( McpsConfirm->McpsRequest==MCPS_CONFIRMED )
+        {     
+            LoRaMacUplinkStatus.Acked = McpsConfirm->AckReceived;
+        }        
+    }
+
+    LoRaMacUplinkStatus.Datarate = McpsConfirm->Datarate;
+    LoRaMacUplinkStatus.UplinkCounter = McpsConfirm->UpLinkCounter;
+    LoRaMacUplinkStatus.TxPower = McpsConfirm->TxPower;
+
+    IsTxIntUpdate = true;
+}
+
+/*!
+ * \brief   MCPS-Indication event function
+ *
+ * \param   [IN] McpsIndication - Pointer to the indication structure,
+ *               containing indication attributes.
+ */
+void McpsIndication( McpsIndication_t *McpsIndication )
+{
+    uint8_t port;
+
+    if( McpsIndication->Status != LORAMAC_EVENT_INFO_STATUS_OK )
+    {
+        return;
+    }
+
+    switch( McpsIndication->McpsIndication )
+    {
+        case MCPS_UNCONFIRMED:
+        {
+            break;
+        }
+        case MCPS_CONFIRMED:
+        {
+            break;
+        }
+        case MCPS_PROPRIETARY:
+        {
+            break;
+        }
+        case MCPS_MULTICAST:
+        {
+            break;
+        }
+        default:
+            break;
+    }
+
+    // Check Multicast
+    // Check Port
+    // Check Datarate
+    // Check FramePending
+    // Check Buffer
+    // Check BufferSize
+    // Check Rssi
+    // Check Snr
+    // Check RxSlot
+    LoRaMacDownlinkStatus.Rssi = McpsIndication->Rssi;
+    if( McpsIndication->Snr & 0x80 ) // The SNR sign bit is 1
+    {
+        // Invert and divide by 4
+        LoRaMacDownlinkStatus.Snr = ( ( ~McpsIndication->Snr + 1 ) & 0xFF ) >> 2;
+        LoRaMacDownlinkStatus.Snr = -LoRaMacDownlinkStatus.Snr;
+    }
+    else
+    {
+        // Divide by 4
+        LoRaMacDownlinkStatus.Snr = ( McpsIndication->Snr & 0xFF ) >> 2;
+    }
+    LoRaMacDownlinkStatus.DownlinkCounter++;
+    LoRaMacDownlinkStatus.RxData = McpsIndication->RxData;      
+    LoRaMacDownlinkStatus.Port = McpsIndication->Port;
+    LoRaMacDownlinkStatus.Buffer = McpsIndication->Buffer;
+    LoRaMacDownlinkStatus.BufferSize = McpsIndication->BufferSize;
+    LoRaMacDownlinkStatus.RxSlot = McpsIndication->RxSlot;
+
+ 
+    
+    if( McpsIndication->RxData == true )
+    {
+        switch( port )
+        {
+        case 1: // The application LED can be controlled on port 1 or 2
+        case 2:            
+            break;
+        default:
+            break;
+        }
+    }
+
+    IsRxUpdate = true;
+
+}
+
+/*!
+ * \brief   MLME-Confirm event function
+ *
+ * \param   [IN] MlmeConfirm - Pointer to the confirm structure,
+ *               containing confirm attributes.
+ */
+void MlmeConfirm( MlmeConfirm_t *MlmeConfirm )
+{
+    if( MlmeConfirm->Status == LORAMAC_EVENT_INFO_STATUS_OK )
+    {
+        if( MlmeConfirm->MlmeRequest==MLME_JOIN )
+        {
+            IsNetworkJoinedStatusUpdate = true;
+        }
+ 
+    }
+
+    // Schedule next packet transmission
+    TimerSetValue( &TxNextPacketTimer, OVER_THE_AIR_ACTIVATION_DUTYCYCLE );
+    TimerStart( &TxNextPacketTimer );
+
+    DeviceState = DEVICE_STATE_SLEEP;
+}
\ No newline at end of file
diff -r 58f66381eb7c -r 54937781831b LoRaMacLayerService.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRaMacLayerService.h	Tue Apr 03 17:01:27 2018 +0000
@@ -0,0 +1,32 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C)2015 Semtech
+
+Description: MAC Layer Services: MLME & MCPS
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainer: Uttam Bhat
+*/
+
+#ifndef __LORA_MAC_LAYER_SERVICE__
+#define __LORA_MAC_LAYER_SERVICE__
+
+#include "board.h"
+#include "LoRaMac.h"
+#include "Common.h"
+
+#include "SerialDisplay.h"
+#include "mbed.h"
+
+
+void McpsConfirm( McpsConfirm_t *McpsConfirm );
+void McpsIndication( McpsIndication_t *McpsIndication );
+void MlmeConfirm( MlmeConfirm_t *MlmeConfirm );
+
+#endif
+