1 前言
我正在陆续对《LoRaWAN102》即LoRaWAN协议规范 V1.0.2 版本(2016年7月定稿)协议的各个章节进行翻译。译文之外还对LoRaWAN协议和源码进行了解析,可点此查看帖子LoRa学习笔记_汇总。
欢迎同行朋友们留言交流。
本文作者twowinter,转载请注明作者:http://blog.csdn.net/iotisan/
2 梳理解析
LoRaWAN第6章,主要对节点加网做了描述,它有两种方式。如果要用一句话来总结的话,那就是这一句了,请看:
如果是空中激活,则需要准备 DevEUI,AppEUI,AppKey 这三个参数,即设备自身MAC地址和要使用的应用(应用ID和密钥)。 如果是ABP激活,则直接配置 DevAddr,NwkSKey,AppSKey 这三个LoRaWAN最终通讯的参数,不再需要join流程。在这种情况下,这个设备是可以直接发应用数据的。
这里插个题外话,商用的LoRaWAN网络一般都是走OTAA流程,这样安全性才得以保证。
(twowinter,你数数,这是一句话?) (如果是空中激活,则需要准备 DevEUI,AppEUI,AppKey来join。如果是ABP激活,则直接配置 DevAddr,NwkSKey,AppSKey。)
3 代码位置
3.1 激活处理
协议的第6章,相关的核心代码是这么几行,位于 srcmacmain.c。 整个代码结构非常清晰,用一个宏(OVER_THE_AIR_ACTIVATION)分开两段,分别对应两种激活方式。
代码语言:javascript复制case DEVICE_STATE_JOIN:
{
#if( OVER_THE_AIR_ACTIVATION != 0 )
MlmeReq_t mlmeReq;
// Initialize LoRaMac device unique ID
BoardGetUniqueId( DevEui );
mlmeReq.Type = MLME_JOIN;
mlmeReq.Req.Join.DevEui = DevEui;
mlmeReq.Req.Join.AppEui = AppEui;
mlmeReq.Req.Join.AppKey = AppKey;
if( NextTx == true )
{
LoRaMacMlmeRequest( &mlmeReq );
}
DeviceState = DEVICE_STATE_SLEEP;
#else
// Choose a random device address if not already defined in Comissioning.h
if( DevAddr == 0 )
{
// Random seed initialization
srand1( BoardGetRandomSeed( ) );
// Choose a random device address
DevAddr = randr( 0, 0x01FFFFFF );
}
mibReq.Type = MIB_NET_ID;
mibReq.Param.NetID = LORAWAN_NETWORK_ID;
LoRaMacMibSetRequestConfirm( &mibReq );
mibReq.Type = MIB_DEV_ADDR;
mibReq.Param.DevAddr = DevAddr;
LoRaMacMibSetRequestConfirm( &mibReq );
mibReq.Type = MIB_NWK_SKEY;
mibReq.Param.NwkSKey = NwkSKey;
LoRaMacMibSetRequestConfirm( &mibReq );
mibReq.Type = MIB_APP_SKEY;
mibReq.Param.AppSKey = AppSKey;
LoRaMacMibSetRequestConfirm( &mibReq );
mibReq.Type = MIB_NETWORK_JOINED;
mibReq.Param.IsNetworkJoined = true;
LoRaMacMibSetRequestConfirm( &mibReq );
DeviceState = DEVICE_STATE_SEND;
#endif
break;
}
3.2 参数配置
关于参数部分,相关的默认值全部位于srcappsLoRaMacclassA硬件平台Comissioning.h 本尊有机会接触了几个LoRaWAN基站厂家,发现大家为了调试方便,一般也会支持这些默认值。
代码语言:javascript复制/*!
* Mote device IEEE EUI (big endian)
*
* remark In this application the value is automatically generated by calling
* BoardGetUniqueId function
*/
#define LORAWAN_DEVICE_EUI { IEEE_OUI, 0x00, 0x00, 0x00, 0x00, 0x00 }
/*!
* Application IEEE EUI (big endian)
*/
#define LORAWAN_APPLICATION_EUI { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
</code></pre>
<pre><code>
/*!
* AES encryption/decryption cipher application key
*/
#define LORAWAN_APPLICATION_KEY { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
/*!
* Current network ID
*/
#define LORAWAN_NETWORK_ID ( uint32_t )0
/*!
* Device address on the network (big endian)
*
* remark In this application the value is automatically generated using
* a pseudo random generator seeded with a value derived from
* BoardUniqueId value if LORAWAN_DEVICE_ADDRESS is set to 0
*/
#define LORAWAN_DEVICE_ADDRESS ( uint32_t )0x00000000
/*!
* AES encryption/decryption cipher network session key
*/
#define LORAWAN_NWKSKEY { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
/*!
* AES encryption/decryption cipher application session key
*/
#define LORAWAN_APPSKEY { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C }
End
That’s all.