forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wisun spesific IE elemts write operation library.
- Loading branch information
Showing
2 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
* Copyright (c) 2018, Arm Limited and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "nsconfig.h" | ||
#include <string.h> | ||
#include "ns_types.h" | ||
#include "ns_list.h" | ||
#include "ns_trace.h" | ||
#include "common_functions.h" | ||
#include "mac_common_defines.h" | ||
#include "6LoWPAN/MAC/mac_ie_lib.h" | ||
#include "6LoWPAN/ws/ws_common_defines.h" | ||
|
||
static uint8_t *ws_wh_header_base_write(uint8_t *ptr, uint16_t length, uint8_t type) | ||
{ | ||
ptr = mac_ie_header_base_write(ptr, MAC_HEADER_ASSIGNED_EXTERNAL_ORG_IE_ID, length + 1); | ||
*ptr++ = type; | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wh_utt_write(uint8_t *ptr, uint8_t message_type) | ||
{ | ||
ptr = ws_wh_header_base_write(ptr, 4, WH_IE_UTT_TYPE); | ||
*ptr++ = message_type; | ||
memset(ptr, 0, 3); | ||
ptr += 3; | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wh_bt_write(uint8_t *ptr) | ||
{ | ||
ptr = ws_wh_header_base_write(ptr, 5, WH_IE_BT_TYPE); | ||
memset(ptr, 0, 5); | ||
ptr += 5; | ||
return ptr; | ||
} | ||
|
||
|
||
uint8_t *ws_wh_fc_write(uint8_t *ptr, uint8_t flow_ctrl) | ||
{ | ||
ptr = ws_wh_header_base_write(ptr, 1, WH_IE_FC_TYPE); | ||
*ptr++ = flow_ctrl; | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wh_rsl_write(uint8_t *ptr, int8_t rssi) | ||
{ | ||
ptr = ws_wh_header_base_write(ptr, 1, WH_IE_RSL_TYPE); | ||
*ptr++ = rssi; | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wh_vh_write(uint8_t *ptr, uint8_t *vendor_header, uint8_t vendor_header_length) | ||
{ | ||
ptr = ws_wh_header_base_write(ptr, vendor_header_length, WH_IE_VH_TYPE); | ||
if (vendor_header_length) { | ||
memcpy(ptr, vendor_header, vendor_header_length); | ||
ptr += vendor_header_length; | ||
} | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wp_base_write(uint8_t *ptr, uint16_t length) | ||
{ | ||
return mac_ie_payload_base_write(ptr, WS_WP_NESTED_IE, length); | ||
} | ||
|
||
uint8_t *ws_wp_nested_us_write(uint8_t *ptr,uint8_t *us_schedule, uint16_t us_schedule_length) | ||
{ | ||
ptr = mac_ie_nested_ie_long_base_write(ptr,WP_PAYLOAD_IE_US_TYPE, us_schedule_length); | ||
if (us_schedule_length) { | ||
memcpy(ptr,us_schedule, us_schedule_length); | ||
ptr += us_schedule_length; | ||
} | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wp_nested_bs_write(uint8_t *ptr, uint8_t *bs_schedule, uint16_t bs_schedule_length) | ||
{ | ||
ptr = mac_ie_nested_ie_long_base_write(ptr,WP_PAYLOAD_IE_BS_TYPE, bs_schedule_length); | ||
if (bs_schedule_length) { | ||
memcpy(ptr,bs_schedule, bs_schedule_length); | ||
ptr += bs_schedule_length; | ||
} | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wp_nested_vp_write(uint8_t *ptr, uint8_t * vendor_payload, uint16_t vendor_payload_length) | ||
{ | ||
ptr = mac_ie_nested_ie_long_base_write(ptr,WP_PAYLOAD_IE_VP_TYPE, vendor_payload_length); | ||
if (vendor_payload_length) { | ||
memcpy(ptr,vendor_payload, vendor_payload_length); | ||
ptr += vendor_payload_length; | ||
} | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wp_nested_pan_info_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration) | ||
{ | ||
if (!pan_congiguration) { | ||
return mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_TYPE, 0); | ||
} | ||
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_TYPE, 5); | ||
ptr = common_write_16_bit(pan_congiguration->pan_size, ptr); | ||
ptr = common_write_16_bit(pan_congiguration->routing_cost, ptr); | ||
uint8_t temp8 = 0; | ||
temp8 |= (pan_congiguration->use_parent_bs << 7); | ||
temp8 |= (pan_congiguration->rpl_routing_method << 6); | ||
temp8 |= pan_congiguration->version; | ||
*ptr++ = temp8; | ||
return ptr; | ||
} | ||
|
||
|
||
uint8_t *ws_wp_nested_netname_write(uint8_t *ptr, uint8_t *network_name, uint8_t network_name_length) | ||
{ | ||
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_NETNAME_TYPE, network_name_length); | ||
if (network_name_length) { | ||
memcpy(ptr,network_name, network_name_length); | ||
ptr += network_name_length; | ||
} | ||
return ptr; | ||
} | ||
|
||
uint8_t *ws_wp_nested_pan_ver_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration) | ||
{ | ||
if (!pan_congiguration) { | ||
return mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_VER_TYPE, 0); | ||
} | ||
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_PAN_VER_TYPE, 2); | ||
return common_write_16_bit(pan_congiguration->pan_version, ptr); | ||
} | ||
|
||
uint8_t *ws_wp_nested_gtkhash_write(uint8_t *ptr, uint8_t *gtkhash, uint8_t gtkhash_length) | ||
{ | ||
ptr = mac_ie_nested_ie_short_base_write(ptr,WP_PAYLOAD_IE_GTKHASH_TYPE, gtkhash_length); | ||
if (gtkhash_length) { | ||
memcpy(ptr, gtkhash, 32); | ||
ptr += 32; | ||
} | ||
return ptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2018, Arm Limited and affiliates. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef WS_IE_LIB_H_ | ||
#define WS_IE_LIB_H_ | ||
|
||
struct ws_pan_information_s; | ||
|
||
/* WS_WH HEADER IE */ | ||
uint8_t *ws_wh_utt_write(uint8_t *ptr, uint8_t message_type); | ||
uint8_t *ws_wh_bt_write(uint8_t *ptr); | ||
uint8_t *ws_wh_fc_write(uint8_t *ptr, uint8_t flow_ctrl); | ||
uint8_t *ws_wh_rsl_write(uint8_t *ptr, int8_t rssi); | ||
uint8_t *ws_wh_vh_write(uint8_t *ptr, uint8_t *vendor_header, uint8_t vendor_header_length); | ||
|
||
/* WS_WP_NESTED PAYLOD IE */ | ||
uint8_t *ws_wp_base_write(uint8_t *ptr, uint16_t length); | ||
uint8_t *ws_wp_nested_us_write(uint8_t *ptr,uint8_t *us_schedule, uint16_t us_schedule_length); | ||
uint8_t *ws_wp_nested_bs_write(uint8_t *ptr, uint8_t *bs_schedule, uint16_t bs_schedule_length); | ||
uint8_t *ws_wp_nested_vp_write(uint8_t *ptr, uint8_t * vendor_payload, uint16_t vendor_payload_length); | ||
uint8_t *ws_wp_nested_pan_info_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration); | ||
uint8_t *ws_wp_nested_netname_write(uint8_t *ptr, uint8_t *network_name, uint8_t network_name_length); | ||
uint8_t *ws_wp_nested_pan_ver_write(uint8_t *ptr, struct ws_pan_information_s *pan_congiguration); | ||
uint8_t *ws_wp_nested_gtkhash_write(uint8_t *ptr, uint8_t *gtkhash, uint8_t gtkhash_length); | ||
|
||
#endif /* WS_IE_LIB_H_ */ |