PicoWAN SDK Documentation
message.h
1 /*
2  * message - The message layer public 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_H_
32 #define _MESSAGE_H_
33 
34 #include "message_common.h"
35 
36 enum ack_request {
37  WITHOUT_ACK,
38  WITH_ACK
39 };
40 
41 typedef enum {
42  MSG_STATUS_FORMAT_ERROR = -4,
43  MSG_STATUS_MIC_ERROR = -3,
44  MSG_STATUS_LENGTH_ERROR = -2,
45  MSG_STATUS_HEADER_ERROR = -1,
46  MSG_STATUS_NO_ERROR = 0,
47 } message_status_t;
48 
53 void message_init_format(message_format_t frame_format);
54 
60 void message_init_session_keys(uint8_t *nwkskey, uint8_t *appskey);
61 
69 void message_init_ids(uint32_t netid, uint32_t devaddr, uint8_t *nwkskey, uint8_t *appskey);
70 
71 
82 message_status_t message_compose(uint8_t type, uint8_t port, const uint8_t *payload, uint8_t payload_len, uint8_t *fopts, uint8_t fopts_len,
83  uint16_t seqno, message_t *msg);
84 
85 
94 message_status_t message_compose_join_OTA(uint8_t type, uint8_t *dev_eui, uint8_t *app_eui, uint16_t *dev_nonce, uint8_t *app_key, message_t *msg);
95 
96 
104 message_status_t message_decode(uint8_t *buf, uint8_t buf_len, message_t *msg);
105 
122 message_status_t message_decode_join_OTA(uint8_t *buf, uint8_t buf_len, uint8_t *app_key, uint8_t *appskey, uint8_t *nwkskey, uint16_t *dev_nonce,
123  uint32_t *netid, uint32_t *devaddr, uint8_t *rx1_dr_offset, uint8_t *rx2_dr, uint8_t *rx_delay,
124  uint8_t *cf_list);
125 
131 message_status_t message_authentication(message_t *msg);
132 
138 enum ack_request message_ack_request(message_t *msg);
139 
145 uint8_t message_get_direction(uint8_t type);
146 
151 uint16_t message_max_payload_length();
152 
160 message_status_t message_get_address(uint8_t *buf, uint8_t buf_len, message_t *msg);
161 
169 message_status_t message_get_header(uint8_t *buf, uint8_t buf_len, message_t *msg);
170 
171 #endif /* _MESSAGE_H_ */
Definition: message_common.h:60