PicoWAN SDK Documentation
message_lora.h
1 /*
2  * message_lora - The LoRaWAN message layer
3  *
4  * Copyright (c) 2018, Archos S.A.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of Archos nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
20  * AND EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL ARCHOS S.A. BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _MESSAGE_LORA_H_
32 #define _MESSAGE_LORA_H_
33 
34 #include <message_common.h>
35 #include <message_interface.h>
36 
40 #define MAX_FCNT_GAP 16384
41 
42 #define MSG_LORA_MAX_FRAME_LEN 256
43 
44 // MHDR + address + FCTRL + fcnt + fopts + fport
45 
46 #define MSG_LORA_MHDR_LEN (sizeof(uint8_t))
47 #define MSG_LORA_MIC_LEN (sizeof(uint32_t))
48 //MAC Payload
49 #define MSG_LORA_ADDR_LEN (sizeof(uint32_t))
50 #define MSG_LORA_FCTRL_LEN (sizeof(uint8_t))
51 #define MSG_LORA_FCNT_LEN (sizeof(uint16_t))
52 #define MSG_LORA_FPORT_LEN (sizeof(uint8_t))
53 //Join Request
54 #define MSG_LORA_APPEUI_LEN (sizeof(uint64_t))
55 #define MSG_LORA_DEVEUI_LEN (sizeof(uint64_t))
56 #define MSG_LORA_DEVNONCE_LEN (sizeof(uint16_t))
57 //Join Accept
58 #define MSG_LORA_APPNONCE_LEN (3*sizeof(uint8_t))
59 #define MSG_LORA_NETID_LEN (3*sizeof(uint8_t))
60 #define MSG_LORA_DLSETTINGS_LEN (sizeof(uint8_t))
61 #define MSG_LORA_RXDELAY_LEN (sizeof(uint8_t))
62 #define MSG_LORA_CFLIST_LEN (16*sizeof(uint8_t))
63 
64 #define MSG_LORA_MIN_MESSAGESIZE (MSG_LORA_MHDR_LEN + MSG_LORA_ADDR_LEN + MSG_LORA_FCTRL_LEN + MSG_LORA_FCNT_LEN + MSG_LORA_MIC_LEN)
65 #define MSG_LORA_REQ_MESSAGESIZE (MSG_LORA_MHDR_LEN + MSG_LORA_APPEUI_LEN + MSG_LORA_DEVEUI_LEN + MSG_LORA_DEVNONCE_LEN + MSG_LORA_MIC_LEN)
66 #define MSG_LORA_ACC_MAX_MESSAGESIZE (MSG_LORA_MHDR_LEN + MSG_LORA_APPNONCE_LEN + MSG_LORA_NETID_LEN + MSG_LORA_ADDR_LEN + MSG_LORA_DLSETTINGS_LEN + MSG_LORA_RXDELAY_LEN + MSG_LORA_CFLIST_LEN + MSG_LORA_MIC_LEN)
67 
68 #define MSG_LORA_FHDR_MIN_LEN (MSG_LORA_ADDR_LEN + MSG_LORA_FCTRL_LEN + MSG_LORA_FCNT_LEN)
69 
70 
71 enum {
72  // Data frame format
73  MSG_LORA_OFF_DAT_MHDR = 0,
74  MSG_LORA_OFF_DAT_FHDR_ADDR = 1,
75  MSG_LORA_OFF_DAT_FHDR_FCTRL = 5,
76  MSG_LORA_OFF_DAT_FHDR_FCNT = 6,
77  MSG_LORA_OFF_DAT_FHDR_FOPTS = 8,
78 };
79 
80 enum {
81  // Data frame format
82  MSG_LORA_OFF_REQ_MHDR = 0,
83  MSG_LORA_OFF_REQ_APPEUI = 1,
84  MSG_LORA_OFF_REQ_DEVEUI = 9,
85  MSG_LORA_OFF_REQ_DEVNONCE = 17,
86 // MSG_LORA_OFF_REQ_MIC = 19,
87 };
88 
89 enum { MSG_LORA_MAX_PAYLOAD_LEN = MSG_LORA_MAX_FRAME_LEN - (int) MSG_LORA_OFF_DAT_FHDR_FOPTS - 4 };
90 
91 enum { MSG_LORA_MHDR_MAJOR_V1 = 0x00,
92 };
93 
94 typedef union {
95  uint8_t value;
96  struct {
97  uint8_t major : 2;
98  uint8_t rfu : 3;
99  uint8_t mtype : 3;
100  } bits;
102 
103 
104 typedef union {
105  uint8_t value;
106  struct {
107  uint8_t foptslen : 4;
108  uint8_t fpending : 1;
109  uint8_t ack : 1;
110  uint8_t adrackreq : 1;
111  uint8_t adr : 1;
112  } bits;
114 
115 typedef struct {
116  message_lora_mhdr_t mhdr;
117  message_lora_fctrl_t fctrl;
118  uint8_t fopts[16];
120 
121 extern message_interface_t message_lora;
122 
123 #endif /* _MESSAGE_LORA_H_ */
Definition: message_lora.h:115
Definition: message_lora.h:104
Definition: message_interface.h:37
Definition: message_lora.h:94