Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 957f270

Browse files
Juha Heiskanenjuhhei01
authored andcommitted
MPX frame support
MPX heeder parser and write support. Module support also fragmentation which could be supported in future. Change-Id: Ic91c2d9ae85b955ebe4881b20929c0251657f319
1 parent 93f0ed7 commit 957f270

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

source/6LoWPAN/ws/ws_mpx_header.c

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
#include "nsconfig.h"
18+
#include <string.h>
19+
#include "ns_types.h"
20+
#include "ns_list.h"
21+
#include "ns_trace.h"
22+
#include "nsdynmemLIB.h"
23+
#include "common_functions.h"
24+
#include "mac_common_defines.h"
25+
#include "ws_mpx_header.h"
26+
27+
bool ws_llc_mpx_header_frame_parse(uint8_t *ptr, uint16_t length, mpx_msg_t *msg)
28+
{
29+
if (!length) {
30+
return false;
31+
}
32+
memset(msg, 0, sizeof(mpx_msg_t));
33+
bool fragmented_number_present = false;
34+
bool multiplex_id_present = false;
35+
bool fragment_total_size = false;
36+
37+
msg->transfer_type = *ptr & 7;
38+
msg->transaction_id = ((*ptr++ & 0xf8) >> 3);
39+
length--;
40+
41+
42+
switch (msg->transfer_type) {
43+
case MPX_FT_FULL_FRAME:
44+
multiplex_id_present = true;
45+
break;
46+
case MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID:
47+
break;
48+
case MPX_FT_FIRST_OR_SUB_FRAGMENT:
49+
case MPX_FT_LAST_FRAGMENT:
50+
fragmented_number_present = true;
51+
if (length < 2) {
52+
return false;
53+
}
54+
break;
55+
case MPX_FT_ABORT:
56+
if (length == 2) {
57+
fragment_total_size = true;
58+
} else if (length) {
59+
return false;
60+
}
61+
break;
62+
default:
63+
return false;
64+
}
65+
66+
if (fragmented_number_present) {
67+
68+
msg->fragment_number = *ptr++;
69+
length--;
70+
if (msg->fragment_number == 0) { //First fragment
71+
fragment_total_size = true;
72+
multiplex_id_present = true;
73+
}
74+
}
75+
76+
if (fragment_total_size) {
77+
if (length < 2) {
78+
return false;
79+
}
80+
msg->total_upper_layer_size = common_read_16_bit_inverse(ptr);
81+
ptr += 2;
82+
length -= 2;
83+
}
84+
85+
if (multiplex_id_present) {
86+
if (length < 3) {
87+
return false;
88+
}
89+
msg->multiplex_id = common_read_16_bit_inverse(ptr);
90+
ptr += 2;
91+
length -= 2;
92+
}
93+
94+
msg->frame_ptr = ptr;
95+
msg->frame_length = length;
96+
return true;
97+
}
98+
99+
100+
uint8_t * ws_llc_mpx_header_write(uint8_t *ptr, const mpx_msg_t *msg)
101+
{
102+
103+
bool fragmented_number_present = false;
104+
bool multiplex_id_present = false;
105+
bool fragment_total_size = false;
106+
107+
*ptr = msg->transfer_type;
108+
*ptr++ |= ((msg->transaction_id << 3) & 0xf8);
109+
110+
switch (msg->transfer_type) {
111+
case MPX_FT_FULL_FRAME:
112+
multiplex_id_present = true;
113+
break;
114+
case MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID:
115+
break;
116+
case MPX_FT_FIRST_OR_SUB_FRAGMENT:
117+
case MPX_FT_LAST_FRAGMENT:
118+
fragmented_number_present = true;
119+
if (msg->fragment_number == 0) {
120+
fragment_total_size = true;
121+
multiplex_id_present = true;
122+
}
123+
break;
124+
case MPX_FT_ABORT:
125+
if (msg->total_upper_layer_size) {
126+
fragment_total_size = true;
127+
}
128+
break;
129+
default:
130+
break;
131+
}
132+
133+
if (fragmented_number_present) {
134+
*ptr++ = msg->fragment_number;
135+
}
136+
137+
if (fragment_total_size) {
138+
ptr = common_write_16_bit_inverse(msg->total_upper_layer_size, ptr);
139+
}
140+
141+
if (multiplex_id_present) {
142+
ptr = common_write_16_bit_inverse(msg->multiplex_id,ptr);
143+
}
144+
return ptr;
145+
}

source/6LoWPAN/ws/ws_mpx_header.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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_MPX_HEADER_H_
19+
#define WS_MPX_HEADER_H_
20+
21+
#define MPX_FT_FULL_FRAME 0
22+
#define MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID 1
23+
#define MPX_FT_FIRST_OR_SUB_FRAGMENT 2
24+
#define MPX_FT_LAST_FRAGMENT 4
25+
#define MPX_FT_ABORT 6
26+
27+
typedef struct {
28+
unsigned transfer_type:3;
29+
unsigned transaction_id:5;
30+
uint8_t fragment_number;
31+
uint16_t total_upper_layer_size;
32+
uint16_t multiplex_id;
33+
uint8_t *frame_ptr;
34+
uint16_t frame_length;
35+
} mpx_msg_t;
36+
37+
bool ws_llc_mpx_header_frame_parse(uint8_t *ptr, uint16_t length, mpx_msg_t *msg);
38+
uint8_t * ws_llc_mpx_header_write(uint8_t *ptr, const mpx_msg_t *msg);
39+
40+
41+
#endif /* WS_MPX_HEADER_H_ */

0 commit comments

Comments
 (0)