PicoWAN SDK Documentation
message_common.h
1 /*
2  * message_common - The message layer private common code
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__COMMON_H_
32 #define _MESSAGE__COMMON_H_
33 
34 #include <stdint.h>
35 
36 #define MSG_MAX_FRAME_LEN 64
37 
38 typedef enum {
39  MSG_FORMAT_EASY = 0,
40  MSG_FORMAT_LORA = 1,
41  MSG_FORMAT_PICOWAN = 2,
42 } message_format_t;
43 
44 enum {
45  MSG_TYPE_JOIN_REQ = 0x00,
46  MSG_TYPE_JOIN_ACCEPT = 0x01,
47  MSG_TYPE_DATA_UNCONFIRMED_UP = 0x02,
48  MSG_TYPE_DATA_UNCONFIRMED_DOWN = 0x03,
49  MSG_TYPE_DATA_CONFIRMED_UP = 0x04,
50  MSG_TYPE_DATA_CONFIRMED_DOWN = 0x05,
51  MSG_TYPE_RFU = 0x06,
52  MSG_TYPE_PROPRIETARY = 0x07,
53 };
54 
55 enum {
56  MSG_UPLINK = 0,
57  MSG_DOWNLINK = 1
58 };
59 
60 typedef struct {
61  uint8_t valid;
62 
63  /*
64  * message type:
65  * 0 for easy format
66  * 1 for lora format
67  * 2 for picowan format
68  */
69  uint8_t format;
70 
71  /*
72  * format version:
73  */
74  uint8_t version;
75 
76  /*
77  * message type:
78  */
79  uint8_t type;
80 
81  /*
82  * port:
83  * 0 is for mac commands else it is application port
84  */
85  uint8_t port;
86 
87  /*
88  * network_id :
89  */
90  uint32_t network_id;
91 
92  /*
93  * devaddr :
94  * accessory network address
95  * Source for messages from accessory
96  * Destination for messages from Gateway
97  * Optional. Depends on type
98  */
99  uint32_t devaddr;
100 
101  /*
102  * seqno :
103  * Sequence number (framecounter)
104  */
105  uint16_t seqno;
106 
107  /*
108  * acknowledge bit:
109  */
110  uint8_t ack;
111 
112  /*
113  * adaptive data rate bit:
114  */
115  uint8_t adr;
116 
117  /*
118  * ADR acknowledgement request bit
119  */
120  uint8_t adr_req;
121 
122  /*
123  * beacon_seed:
124  */
125  uint8_t beacon_seed;
126 
127  /*
128  * message length:
129  * length of the payload + headers + MIC
130  */
131  uint8_t msg_len;
132 
133  /*
134  * Payload length:
135  * length of the payload to follow in bytes _NOT_ including MIC
136  */
137  uint8_t payload_len;
138 
139  /*
140  * Payload:
141  * uint8_t* to the data which were received
142  */
143  uint8_t *payload;
144 
145  /*
146  * Fopts length:
147  * length of MAC commands
148  */
149  uint8_t fopts_len;
150 
151  /*
152  * Fopts: contain MAC commands
153  * uint8_t* to commands which were received
154  */
155  uint8_t *fopts;
156 
157  /*
158  * Raw data
159  */
160  uint8_t raw[MSG_MAX_FRAME_LEN];
161 } message_t;
162 
163 
164 #endif
Definition: message_common.h:60