Skip to content

Commit 5d9a379

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
Wisun spesific IE elemts write operation library.
1 parent b4e1616 commit 5d9a379

File tree

2 files changed

+196
-0
lines changed

2 files changed

+196
-0
lines changed

source/6LoWPAN/ws/ws_ie_lib.c

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "nsconfig.h"
19+
#include <string.h>
20+
#include "ns_types.h"
21+
#include "ns_list.h"
22+
#include "ns_trace.h"
23+
#include "common_functions.h"
24+
#include "mac_common_defines.h"
25+
#include "6LoWPAN/MAC/mac_ie_lib.h"
26+
#include "6LoWPAN/ws/ws_common_defines.h"
27+
28+
static uint8_t *ws_wh_header_base_write(uint8_t *ptr, uint16_t length, uint8_t type)
29+
{
30+
ptr = mac_ie_header_base_write(ptr, MAC_HEADER_ASSIGNED_EXTERNAL_ORG_IE_ID, length + 1);
31+
*ptr++ = type;
32+
return ptr;
33+
}
34+
35+
uint8_t *ws_wh_utt_write(uint8_t *ptr, uint8_t message_type)
36+
{
37+
ptr = ws_wh_header_base_write(ptr, 4, WH_IE_UTT_TYPE);
38+
*ptr++ = message_type;
39+
memset(ptr, 0, 3);
40+
ptr += 3;
41+
return ptr;
42+
}
43+
44+
uint8_t *ws_wh_bt_write(uint8_t *ptr)
45+
{
46+
ptr = ws_wh_header_base_write(ptr, 5, WH_IE_BT_TYPE);
47+
memset(ptr, 0, 5);
48+
ptr += 5;
49+
return ptr;
50+
}
51+
52+
53+
uint8_t *ws_wh_fc_write(uint8_t *ptr, uint8_t flow_ctrl)
54+
{
55+
ptr = ws_wh_header_base_write(ptr, 1, WH_IE_FC_TYPE);
56+
*ptr++ = flow_ctrl;
57+
return ptr;
58+
}
59+
60+
uint8_t *ws_wh_rsl_write(uint8_t *ptr, int8_t rssi)
61+
{
62+
ptr = ws_wh_header_base_write(ptr, 1, WH_IE_RSL_TYPE);
63+
*ptr++ = rssi;
64+
return ptr;
65+
}
66+
67+
uint8_t *ws_wh_vh_write(uint8_t *ptr, uint8_t *vendor_header, uint8_t vendor_header_length)
68+
{
69+
ptr = ws_wh_header_base_write(ptr, vendor_header_length, WH_IE_VH_TYPE);
70+
if (vendor_header_length) {
71+
memcpy(ptr, vendor_header, vendor_header_length);
72+
ptr += vendor_header_length;
73+
}
74+
return ptr;
75+
}
76+
77+
uint8_t *ws_wp_base_write(uint8_t *ptr, uint16_t length)
78+
{
79+
return mac_ie_payload_base_write(ptr, WS_WP_NESTED_IE, length);
80+
}
81+
82+
uint8_t *ws_wp_nested_us_write(uint8_t *ptr,uint8_t *us_schedule, uint16_t us_schedule_length)
83+
{
84+
ptr = mac_ie_nested_ie_long_base_write(ptr,WP_PAYLOAD_IE_US_TYPE, us_schedule_length);
85+
if (us_schedule_length) {
86+
memcpy(ptr,us_schedule, us_schedule_length);
87+
ptr += us_schedule_length;
88+
}
89+
return ptr;
90+
}
91+
92+
uint8_t *ws_wp_nested_bs_write(uint8_t *ptr, uint8_t *bs_schedule, uint16_t bs_schedule_length)
93+
{
94+
ptr = mac_ie_nested_ie_long_base_write(ptr,WP_PAYLOAD_IE_BS_TYPE, bs_schedule_length);
95+
if (bs_schedule_length) {
96+
memcpy(ptr,bs_schedule, bs_schedule_length);
97+
ptr += bs_schedule_length;
98+
}
99+
return ptr;
100+
}
101+
102+
uint8_t *ws_wp_nested_vp_write(uint8_t *ptr, uint8_t * vendor_payload, uint16_t vendor_payload_length)
103+
{
104+
ptr = mac_ie_nested_ie_long_base_write(ptr,WP_PAYLOAD_IE_VP_TYPE, vendor_payload_length);
105+
if (vendor_payload_length) {
106+
memcpy(ptr,vendor_payload, vendor_payload_length);
107+
ptr += vendor_payload_length;
108+
}
109+
return ptr;
110+
}
111+
112+
uint8_t *ws_wp_nested_pan_info_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration)
113+
{
114+
if (!pan_congiguration) {
115+
return mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_TYPE, 0);
116+
}
117+
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_TYPE, 5);
118+
ptr = common_write_16_bit(pan_congiguration->pan_size, ptr);
119+
ptr = common_write_16_bit(pan_congiguration->routing_cost, ptr);
120+
uint8_t temp8 = 0;
121+
temp8 |= (pan_congiguration->use_parent_bs << 7);
122+
temp8 |= (pan_congiguration->rpl_routing_method << 6);
123+
temp8 |= pan_congiguration->version;
124+
*ptr++ = temp8;
125+
return ptr;
126+
}
127+
128+
129+
uint8_t *ws_wp_nested_netname_write(uint8_t *ptr, uint8_t *network_name, uint8_t network_name_length)
130+
{
131+
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_NETNAME_TYPE, network_name_length);
132+
if (network_name_length) {
133+
memcpy(ptr,network_name, network_name_length);
134+
ptr += network_name_length;
135+
}
136+
return ptr;
137+
}
138+
139+
uint8_t *ws_wp_nested_pan_ver_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration)
140+
{
141+
if (!pan_congiguration) {
142+
return mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_VER_TYPE, 0);
143+
}
144+
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_VER_TYPE, 2);
145+
return common_write_16_bit(pan_congiguration->pan_version, ptr);
146+
}
147+
148+
uint8_t *ws_wp_nested_gtkhash_write(uint8_t *ptr, uint8_t *gtkhash, uint8_t gtkhash_length)
149+
{
150+
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_GTKHASH_TYPE, gtkhash_length);
151+
if (gtkhash_length) {
152+
memcpy(ptr, gtkhash, 32);
153+
ptr += 32;
154+
}
155+
return ptr;
156+
}

source/6LoWPAN/ws/ws_ie_lib.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef WS_IE_LIB_H_
19+
#define WS_IE_LIB_H_
20+
21+
struct ws_pan_information_s;
22+
23+
/* WS_WH HEADER IE */
24+
uint8_t *ws_wh_utt_write(uint8_t *ptr, uint8_t message_type);
25+
uint8_t *ws_wh_bt_write(uint8_t *ptr);
26+
uint8_t *ws_wh_fc_write(uint8_t *ptr, uint8_t flow_ctrl);
27+
uint8_t *ws_wh_rsl_write(uint8_t *ptr, int8_t rssi);
28+
uint8_t *ws_wh_vh_write(uint8_t *ptr, uint8_t *vendor_header, uint8_t vendor_header_length);
29+
30+
/* WS_WP_NESTED PAYLOD IE */
31+
uint8_t *ws_wp_base_write(uint8_t *ptr, uint16_t length);
32+
uint8_t *ws_wp_nested_us_write(uint8_t *ptr,uint8_t *us_schedule, uint16_t us_schedule_length);
33+
uint8_t *ws_wp_nested_bs_write(uint8_t *ptr, uint8_t *bs_schedule, uint16_t bs_schedule_length);
34+
uint8_t *ws_wp_nested_vp_write(uint8_t *ptr, uint8_t * vendor_payload, uint16_t vendor_payload_length);
35+
uint8_t *ws_wp_nested_pan_info_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration);
36+
uint8_t *ws_wp_nested_netname_write(uint8_t *ptr, uint8_t *network_name, uint8_t network_name_length);
37+
uint8_t *ws_wp_nested_pan_ver_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration);
38+
uint8_t *ws_wp_nested_gtkhash_write(uint8_t *ptr, uint8_t *gtkhash, uint8_t gtkhash_length);
39+
40+
#endif /* WS_IE_LIB_H_ */

0 commit comments

Comments
 (0)