|
| 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 "6LoWPAN/ws/ws_mpx_header.h" |
| 26 | +#include "common_functions_stub.h" |
| 27 | + |
| 28 | +bool test_ws_llc_mpx_header_frame_parse() |
| 29 | +{ |
| 30 | + mpx_msg_t mpx_msg; |
| 31 | + uint8_t temp_buffer[10]; |
| 32 | + |
| 33 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 0, &mpx_msg) ) { |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + temp_buffer[0] = MPX_FT_FULL_FRAME; |
| 38 | + temp_buffer[0] |= (15 << 3); |
| 39 | + |
| 40 | + common_functions_stub.readuint16_from_queue = 0; |
| 41 | + common_functions_stub.uint16_value = 4; |
| 42 | + |
| 43 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 2, &mpx_msg) ) { |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + if (!ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) { |
| 48 | + return false; |
| 49 | + } |
| 50 | + |
| 51 | + if (mpx_msg.frame_length != 2 || mpx_msg.frame_ptr != &temp_buffer[3] || mpx_msg.transfer_type != MPX_FT_FULL_FRAME || mpx_msg.transaction_id != 15 || mpx_msg.multiplex_id != 4) { |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + temp_buffer[0] = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID; |
| 56 | + temp_buffer[0] |= (16 << 3); |
| 57 | + |
| 58 | + if (!ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) { |
| 59 | + return false; |
| 60 | + } |
| 61 | + |
| 62 | + if (mpx_msg.frame_length != 4 || mpx_msg.frame_ptr != &temp_buffer[1] || mpx_msg.transfer_type != MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID || mpx_msg.transaction_id != 16) { |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + temp_buffer[0] = MPX_FT_FIRST_OR_SUB_FRAGMENT; |
| 67 | + temp_buffer[0] |= (17 << 3); |
| 68 | + temp_buffer[1] = 0; |
| 69 | + |
| 70 | + common_functions_stub.readuint16_from_queue = 2; |
| 71 | + //common_functions_stub.uint16_value = 100; |
| 72 | + common_functions_stub.uint16_value_queue[1] = 40; |
| 73 | + common_functions_stub.uint16_value_queue[0] = 20; |
| 74 | + |
| 75 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 2, &mpx_msg) ) { |
| 76 | + return false; |
| 77 | + } |
| 78 | + common_functions_stub.readuint16_from_queue = 2; |
| 79 | + common_functions_stub.uint16_value_queue[1] = 40; |
| 80 | + common_functions_stub.uint16_value_queue[0] = 20; |
| 81 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) { |
| 82 | + return false; |
| 83 | + } |
| 84 | + common_functions_stub.readuint16_from_queue = 2; |
| 85 | + common_functions_stub.uint16_value_queue[1] = 40; |
| 86 | + common_functions_stub.uint16_value_queue[0] = 20; |
| 87 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 5, &mpx_msg) ) { |
| 88 | + return false; |
| 89 | + } |
| 90 | + common_functions_stub.readuint16_from_queue = 2; |
| 91 | + common_functions_stub.uint16_value_queue[1] = 40; |
| 92 | + common_functions_stub.uint16_value_queue[0] = 20; |
| 93 | + |
| 94 | + |
| 95 | + if (!ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) { |
| 96 | + return false; |
| 97 | + } |
| 98 | + |
| 99 | + if (mpx_msg.frame_length != 4 || mpx_msg.frame_ptr != &temp_buffer[6] || mpx_msg.transfer_type != MPX_FT_FIRST_OR_SUB_FRAGMENT |
| 100 | + || mpx_msg.transaction_id != 17 || mpx_msg.multiplex_id != 20 || mpx_msg.total_upper_layer_size != 40) { |
| 101 | + return false; |
| 102 | + } |
| 103 | + |
| 104 | + temp_buffer[0] = MPX_FT_FIRST_OR_SUB_FRAGMENT; |
| 105 | + temp_buffer[0] |= (18 << 3); |
| 106 | + temp_buffer[1] = 1; |
| 107 | + |
| 108 | + if (!ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) { |
| 109 | + return false; |
| 110 | + } |
| 111 | + |
| 112 | + if (mpx_msg.frame_length != 8 || mpx_msg.frame_ptr != &temp_buffer[2] || mpx_msg.transfer_type != MPX_FT_FIRST_OR_SUB_FRAGMENT |
| 113 | + || mpx_msg.transaction_id != 18 ) { |
| 114 | + return false; |
| 115 | + } |
| 116 | + temp_buffer[0] = MPX_FT_ABORT; |
| 117 | + temp_buffer[0] |= (19 << 3); |
| 118 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 10, &mpx_msg) ) { |
| 119 | + return false; |
| 120 | + } |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + common_functions_stub.readuint16_from_queue = 0; |
| 125 | + common_functions_stub.uint16_value = 400; |
| 126 | + |
| 127 | + if (!ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) { |
| 128 | + return false; |
| 129 | + } |
| 130 | + |
| 131 | + if (mpx_msg.frame_length || mpx_msg.transfer_type != MPX_FT_ABORT |
| 132 | + || mpx_msg.transaction_id != 19 || mpx_msg.total_upper_layer_size != 400) { |
| 133 | + return false; |
| 134 | + } |
| 135 | + if (!ws_llc_mpx_header_frame_parse(temp_buffer, 1, &mpx_msg) ) { |
| 136 | + return false; |
| 137 | + } |
| 138 | + |
| 139 | + if (mpx_msg.frame_length || mpx_msg.transfer_type != MPX_FT_ABORT |
| 140 | + || mpx_msg.transaction_id != 19 || mpx_msg.total_upper_layer_size) { |
| 141 | + return false; |
| 142 | + } |
| 143 | + |
| 144 | + temp_buffer[0] = 7; |
| 145 | + temp_buffer[0] |= (19 << 3); |
| 146 | + if (ws_llc_mpx_header_frame_parse(temp_buffer, 3, &mpx_msg) ) { |
| 147 | + return false; |
| 148 | + } |
| 149 | + |
| 150 | + |
| 151 | + return true; |
| 152 | +} |
| 153 | + |
| 154 | +bool test_ws_llc_mpx_header_write() |
| 155 | +{ |
| 156 | + mpx_msg_t mpx_msg; |
| 157 | + uint8_t temp_buffer[10]; |
| 158 | + |
| 159 | + mpx_msg.transfer_type = MPX_FT_FULL_FRAME; |
| 160 | + mpx_msg.transaction_id = 15; |
| 161 | + |
| 162 | + uint8_t *ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 163 | + if (ptr != &temp_buffer[3]) { |
| 164 | + return false; |
| 165 | + } |
| 166 | + |
| 167 | + mpx_msg.transfer_type = MPX_FT_FULL_FRAME_SMALL_MULTILEX_ID; |
| 168 | + ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 169 | + if (ptr != &temp_buffer[1]) { |
| 170 | + return false; |
| 171 | + } |
| 172 | + |
| 173 | + mpx_msg.transfer_type = MPX_FT_FIRST_OR_SUB_FRAGMENT; |
| 174 | + mpx_msg.fragment_number = 0; |
| 175 | + ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 176 | + if (ptr != &temp_buffer[6]) { |
| 177 | + return false; |
| 178 | + } |
| 179 | + |
| 180 | + mpx_msg.transfer_type = MPX_FT_FIRST_OR_SUB_FRAGMENT; |
| 181 | + mpx_msg.fragment_number = 1; |
| 182 | + ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 183 | + if (ptr != &temp_buffer[2]) { |
| 184 | + return false; |
| 185 | + } |
| 186 | + |
| 187 | + mpx_msg.transfer_type = MPX_FT_ABORT; |
| 188 | + mpx_msg.total_upper_layer_size = 0; |
| 189 | + ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 190 | + if (ptr != &temp_buffer[1]) { |
| 191 | + return false; |
| 192 | + } |
| 193 | + |
| 194 | + mpx_msg.transfer_type = MPX_FT_ABORT; |
| 195 | + mpx_msg.total_upper_layer_size = 400; |
| 196 | + ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 197 | + if (ptr != &temp_buffer[3]) { |
| 198 | + return false; |
| 199 | + } |
| 200 | + |
| 201 | + mpx_msg.transfer_type = 7; |
| 202 | + ptr = ws_llc_mpx_header_write(temp_buffer, &mpx_msg); |
| 203 | + if (ptr != &temp_buffer[1]) { |
| 204 | + return false; |
| 205 | + } |
| 206 | + |
| 207 | + return true; |
| 208 | +} |
0 commit comments