bhh_pack.c (20201B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: bhh_pack.c 8 * Purpose: BHH pack and unpack routines for: 9 * - BHH Control messages 10 * - Network Packet headers (PDUs) 11 * 12 * 13 * BHH control messages 14 * 15 * BHH messages between the Host CPU and uController are sent 16 * using the uc_message module which allows short messages 17 * to be passed (see include/soc/shared/mos_msg_common.h) 18 * 19 * Additional information for a given message (a long message) is passed 20 * using DMA. The BHH control message types defines the format 21 * for these long messages. 22 * 23 * This file is shared between SDK and uKernel. 24 */ 25 26 #include <shared/pack.h> 27 #include <soc/shared/bhh_msg.h> 28 #include <soc/shared/bhh_pkt.h> 29 #include <soc/shared/bhh_pack.h> 30 31 32 /*********************************************************** 33 * BHH Control Message Pack/Unpack 34 * 35 * Functions: 36 * shr_bhh_msg_ctrl_<type>_pack/unpack 37 * Purpose: 38 * The following set of routines pack/unpack specified 39 * BHH control message into/from a given buffer 40 * Parameters: 41 * _pack() 42 * buffer - (OUT) Buffer where to pack message. 43 * msg - (IN) BHH control message to pack. 44 * _unpack() 45 * buffer - (IN) Buffer with message to unpack. 46 * msg - (OUT) Returns BHH control message. 47 * Returns: 48 * Pointer to next position in buffer. 49 * Notes: 50 * Assumes pointers are valid and contain enough memory space. 51 */ 52 uint8 * 53 shr_bhh_msg_ctrl_init_pack(uint8 *buf, shr_bhh_msg_ctrl_init_t *msg) 54 { 55 int i; 56 57 _SHR_PACK_U32(buf, msg->num_sessions); 58 _SHR_PACK_U32(buf, msg->rx_channel); 59 _SHR_PACK_U32(buf, msg->node_id); 60 for (i = 0;i < SHR_BHH_CARRIER_CODE_LEN;i++) 61 _SHR_PACK_U8(buf, msg->carrier_code[i]); 62 63 return buf; 64 } 65 66 uint8 * 67 shr_bhh_msg_ctrl_init_unpack(uint8 *buf, shr_bhh_msg_ctrl_init_t *msg) 68 { 69 int i; 70 71 _SHR_UNPACK_U32(buf, msg->num_sessions); 72 _SHR_UNPACK_U32(buf, msg->rx_channel); 73 _SHR_UNPACK_U32(buf, msg->node_id); 74 for (i = 0;i < SHR_BHH_CARRIER_CODE_LEN;i++) 75 _SHR_UNPACK_U8(buf, msg->carrier_code[i]); 76 77 return buf; 78 } 79 80 81 uint8 * 82 shr_bhh_msg_ctrl_sess_delete_pack(uint8 *buf, shr_bhh_msg_ctrl_sess_delete_t *msg) 83 { 84 _SHR_PACK_U32(buf, msg->sess_id); 85 return buf; 86 } 87 88 uint8 * 89 shr_bhh_msg_ctrl_sess_delete_unpack(uint8 *buf, shr_bhh_msg_ctrl_sess_delete_t *msg) 90 { 91 _SHR_UNPACK_U32(buf, msg->sess_id); 92 return buf; 93 } 94 95 uint8 * 96 shr_bhh_msg_ctrl_sess_enable_pack(uint8 *buf, shr_bhh_msg_ctrl_sess_enable_t *msg) 97 { 98 _SHR_PACK_U32(buf, msg->sess_id); 99 _SHR_PACK_U32(buf, msg->flags); 100 _SHR_PACK_U16(buf, msg->remote_mep_id); 101 _SHR_PACK_U8(buf, msg->enable); 102 103 return buf; 104 } 105 106 uint8 * 107 shr_bhh_msg_ctrl_sess_enable_unpack(uint8 *buf, shr_bhh_msg_ctrl_sess_enable_t *msg) 108 { 109 _SHR_UNPACK_U32(buf, msg->sess_id); 110 _SHR_UNPACK_U32(buf, msg->flags); 111 _SHR_UNPACK_U16(buf, msg->remote_mep_id); 112 _SHR_UNPACK_U8(buf, msg->enable); 113 114 return buf; 115 } 116 117 uint8 * 118 shr_bhh_msg_ctrl_sess_set_pack(uint8 *buf, 119 shr_bhh_msg_ctrl_sess_set_t *msg) 120 { 121 uint16 i; 122 123 _SHR_PACK_U32(buf, msg->sess_id); 124 _SHR_PACK_U32(buf, msg->flags); 125 _SHR_PACK_U8(buf, msg->passive); 126 _SHR_PACK_U8(buf, msg->mel); 127 _SHR_PACK_U16(buf, msg->mep_id); 128 for (i = 0; i < SHR_BHH_MEG_ID_LENGTH; i++) { 129 _SHR_PACK_U8(buf, msg->meg_id[i]); 130 } 131 _SHR_PACK_U32(buf, msg->period); 132 _SHR_PACK_U8(buf, msg->encap_type); 133 _SHR_PACK_U32(buf, msg->encap_length); 134 for (i = 0; i < SHR_BHH_MAX_ENCAP_LENGTH; i++) { 135 _SHR_PACK_U8(buf, msg->encap_data[i]); 136 } 137 _SHR_PACK_U32(buf, msg->tx_port); 138 _SHR_PACK_U32(buf, msg->tx_cos); 139 _SHR_PACK_U32(buf, msg->tx_pri); 140 _SHR_PACK_U32(buf, msg->tx_qnum); 141 _SHR_PACK_U32(buf, msg->mpls_label); 142 _SHR_PACK_U32(buf, msg->if_num); 143 _SHR_PACK_U32(buf, msg->lm_counter_index); 144 145 return buf; 146 } 147 148 uint8 * 149 shr_bhh_msg_ctrl_sess_set_unpack(uint8 *buf, 150 shr_bhh_msg_ctrl_sess_set_t *msg) 151 { 152 uint16 i; 153 154 _SHR_UNPACK_U32(buf, msg->sess_id); 155 _SHR_UNPACK_U32(buf, msg->flags); 156 _SHR_UNPACK_U8(buf, msg->passive); 157 _SHR_UNPACK_U8(buf, msg->mel); 158 _SHR_UNPACK_U16(buf, msg->mep_id); 159 for (i = 0; i < SHR_BHH_MEG_ID_LENGTH; i++) { 160 _SHR_UNPACK_U8(buf, msg->meg_id[i]); 161 } 162 _SHR_UNPACK_U32(buf, msg->period); 163 _SHR_UNPACK_U8(buf, msg->encap_type); 164 _SHR_UNPACK_U32(buf, msg->encap_length); 165 for (i = 0; i < SHR_BHH_MAX_ENCAP_LENGTH; i++) { 166 _SHR_UNPACK_U8(buf, msg->encap_data[i]); 167 } 168 _SHR_UNPACK_U32(buf, msg->tx_port); 169 _SHR_UNPACK_U32(buf, msg->tx_cos); 170 _SHR_UNPACK_U32(buf, msg->tx_pri); 171 _SHR_UNPACK_U32(buf, msg->tx_qnum); 172 _SHR_UNPACK_U32(buf, msg->mpls_label); 173 _SHR_UNPACK_U32(buf, msg->if_num); 174 _SHR_UNPACK_U32(buf, msg->lm_counter_index); 175 176 return buf; 177 } 178 179 180 181 uint8 * 182 shr_bhh_msg_ctrl_sess_get_pack(uint8 *buf, 183 shr_bhh_msg_ctrl_sess_get_t *msg) 184 { 185 int i; 186 187 _SHR_PACK_U32(buf, msg->sess_id); 188 _SHR_PACK_U8(buf, msg->enable); 189 _SHR_PACK_U8(buf, msg->passive); 190 _SHR_PACK_U8(buf, msg->local_demand); 191 _SHR_PACK_U8(buf, msg->remote_demand); 192 _SHR_PACK_U8(buf, msg->local_sess_state); 193 _SHR_PACK_U8(buf, msg->remote_sess_state); 194 _SHR_PACK_U8(buf, msg->mel); 195 _SHR_PACK_U16(buf, msg->mep_id); 196 for (i = 0; i < SHR_BHH_MEG_ID_LENGTH; i++) { 197 _SHR_PACK_U8(buf, msg->meg_id[i]); 198 } 199 _SHR_PACK_U32(buf, msg->period); 200 _SHR_PACK_U8(buf, msg->encap_type); 201 _SHR_PACK_U32(buf, msg->encap_length); 202 for (i = 0; i < SHR_BHH_MAX_ENCAP_LENGTH; i++) { 203 _SHR_PACK_U8(buf, msg->encap_data[i]); 204 } 205 _SHR_PACK_U32(buf, msg->tx_port); 206 _SHR_PACK_U32(buf, msg->tx_cos); 207 _SHR_PACK_U32(buf, msg->tx_pri); 208 _SHR_PACK_U32(buf, msg->tx_qnum); 209 210 return buf; 211 } 212 213 uint8 * 214 shr_bhh_msg_ctrl_stat_req_pack(uint8 *buf, 215 shr_bhh_msg_ctrl_stat_req_t *msg) 216 { 217 _SHR_PACK_U32(buf, msg->sess_id); 218 _SHR_PACK_U32(buf, msg->clear); 219 220 return buf; 221 } 222 223 uint8 * 224 shr_bhh_msg_ctrl_stat_req_unpack(uint8 *buf, 225 shr_bhh_msg_ctrl_stat_req_t *msg) 226 { 227 _SHR_UNPACK_U32(buf, msg->sess_id); 228 _SHR_UNPACK_U32(buf, msg->clear); 229 230 return buf; 231 } 232 233 uint8 * 234 shr_bhh_msg_ctrl_stat_reply_pack(uint8 *buf, 235 shr_bhh_msg_ctrl_stat_reply_t *msg) 236 { 237 _SHR_PACK_U32(buf, msg->sess_id); 238 _SHR_PACK_U32(buf, msg->packets_in); 239 _SHR_PACK_U32(buf, msg->packets_out); 240 _SHR_PACK_U32(buf, msg->packets_drop); 241 _SHR_PACK_U32(buf, msg->packets_auth_drop); 242 243 return buf; 244 } 245 246 uint8 * 247 shr_bhh_msg_ctrl_stat_reply_unpack(uint8 *buf, 248 shr_bhh_msg_ctrl_stat_reply_t *msg) 249 { 250 _SHR_UNPACK_U32(buf, msg->sess_id); 251 _SHR_UNPACK_U32(buf, msg->packets_in); 252 _SHR_UNPACK_U32(buf, msg->packets_out); 253 _SHR_UNPACK_U32(buf, msg->packets_drop); 254 _SHR_UNPACK_U32(buf, msg->packets_auth_drop); 255 256 return buf; 257 } 258 259 uint8 * 260 shr_bhh_msg_ctrl_loopback_add_pack(uint8 *buf, 261 shr_bhh_msg_ctrl_loopback_add_t *msg) 262 { 263 _SHR_PACK_U32(buf, msg->flags); 264 _SHR_PACK_U32(buf, msg->sess_id); 265 _SHR_PACK_U32(buf, msg->period); 266 _SHR_PACK_U32(buf, msg->ttl); 267 268 return buf; 269 } 270 271 uint8 * 272 shr_bhh_msg_ctrl_loopback_add_unpack(uint8 *buf, 273 shr_bhh_msg_ctrl_loopback_add_t *msg) 274 { 275 _SHR_UNPACK_U32(buf, msg->flags); 276 _SHR_UNPACK_U32(buf, msg->sess_id); 277 _SHR_UNPACK_U32(buf, msg->period); 278 _SHR_UNPACK_U32(buf, msg->ttl); 279 280 return buf; 281 } 282 283 uint8 * 284 shr_bhh_msg_ctrl_loopback_delete_pack(uint8 *buf, 285 shr_bhh_msg_ctrl_loopback_delete_t *msg) 286 { 287 _SHR_PACK_U32(buf, msg->sess_id); 288 289 return buf; 290 } 291 292 uint8 * 293 shr_bhh_msg_ctrl_loopback_delete_unpack(uint8 *buf, 294 shr_bhh_msg_ctrl_loopback_delete_t *msg) 295 { 296 _SHR_UNPACK_U32(buf, msg->sess_id); 297 298 return buf; 299 } 300 301 uint8 * 302 shr_bhh_msg_ctrl_loopback_get_pack(uint8 *buf, 303 shr_bhh_msg_ctrl_loopback_get_t *msg) 304 { 305 _SHR_PACK_U32(buf, msg->flags); 306 _SHR_PACK_U32(buf, msg->sess_id); 307 _SHR_PACK_U32(buf, msg->period); 308 _SHR_PACK_U32(buf, msg->ttl); 309 _SHR_PACK_U32(buf, msg->discovery_flags); 310 _SHR_PACK_U32(buf, msg->discovery_id); 311 _SHR_PACK_U32(buf, msg->discovery_ttl); 312 _SHR_PACK_U32(buf, msg->rx_count); 313 _SHR_PACK_U32(buf, msg->tx_count); 314 _SHR_PACK_U32(buf, msg->drop_count); 315 _SHR_PACK_U32(buf, msg->unexpected_response); 316 _SHR_PACK_U32(buf, msg->out_of_sequence); 317 _SHR_PACK_U32(buf, msg->local_mipid_missmatch); 318 _SHR_PACK_U32(buf, msg->remote_mipid_missmatch); 319 _SHR_PACK_U32(buf, msg->invalid_target_mep_tlv); 320 _SHR_PACK_U32(buf, msg->invalid_mep_tlv_subtype); 321 _SHR_PACK_U32(buf, msg->invalid_tlv_offset); 322 323 return buf; 324 } 325 326 uint8 * 327 shr_bhh_msg_ctrl_loopback_get_unpack(uint8 *buf, 328 shr_bhh_msg_ctrl_loopback_get_t *msg) 329 { 330 _SHR_UNPACK_U32(buf, msg->flags); 331 _SHR_UNPACK_U32(buf, msg->sess_id); 332 _SHR_UNPACK_U32(buf, msg->period); 333 _SHR_UNPACK_U32(buf, msg->ttl); 334 _SHR_UNPACK_U32(buf, msg->discovery_flags); 335 _SHR_UNPACK_U32(buf, msg->discovery_id); 336 _SHR_UNPACK_U32(buf, msg->discovery_ttl); 337 _SHR_UNPACK_U32(buf, msg->rx_count); 338 _SHR_UNPACK_U32(buf, msg->tx_count); 339 _SHR_UNPACK_U32(buf, msg->drop_count); 340 _SHR_UNPACK_U32(buf, msg->unexpected_response); 341 _SHR_UNPACK_U32(buf, msg->out_of_sequence); 342 _SHR_UNPACK_U32(buf, msg->local_mipid_missmatch); 343 _SHR_UNPACK_U32(buf, msg->remote_mipid_missmatch); 344 _SHR_UNPACK_U32(buf, msg->invalid_target_mep_tlv); 345 _SHR_UNPACK_U32(buf, msg->invalid_mep_tlv_subtype); 346 _SHR_UNPACK_U32(buf, msg->invalid_tlv_offset); 347 return buf; 348 } 349 350 uint8 * 351 shr_bhh_msg_ctrl_loss_add_pack(uint8 *buf, 352 shr_bhh_msg_ctrl_loss_add_t *msg) 353 { 354 _SHR_PACK_U32(buf, msg->flags); 355 _SHR_PACK_U32(buf, msg->sess_id); 356 _SHR_PACK_U32(buf, msg->period); 357 _SHR_PACK_U32(buf, msg->int_pri); 358 _SHR_PACK_U8 (buf, msg->pkt_pri); 359 360 return buf; 361 } 362 363 uint8 * 364 shr_bhh_msg_ctrl_loss_add_unpack(uint8 *buf, 365 shr_bhh_msg_ctrl_loss_add_t *msg) 366 { 367 _SHR_UNPACK_U32(buf, msg->flags); 368 _SHR_UNPACK_U32(buf, msg->sess_id); 369 _SHR_UNPACK_U32(buf, msg->period); 370 _SHR_UNPACK_U32(buf, msg->int_pri); 371 _SHR_UNPACK_U8 (buf, msg->pkt_pri); 372 373 return buf; 374 } 375 376 uint8 * 377 shr_bhh_msg_ctrl_loss_delete_pack(uint8 *buf, 378 shr_bhh_msg_ctrl_loss_delete_t *msg) 379 { 380 _SHR_PACK_U32(buf, msg->sess_id); 381 382 return buf; 383 } 384 385 uint8 * 386 shr_bhh_msg_ctrl_loss_delete_unpack(uint8 *buf, 387 shr_bhh_msg_ctrl_loss_delete_t *msg) 388 { 389 _SHR_UNPACK_U32(buf, msg->sess_id); 390 391 return buf; 392 } 393 394 uint8 * 395 shr_bhh_msg_ctrl_loss_get_pack(uint8 *buf, 396 shr_bhh_msg_ctrl_loss_get_t *msg) 397 { 398 _SHR_PACK_U32(buf, msg->flags); 399 _SHR_PACK_U32(buf, msg->sess_id); 400 _SHR_PACK_U32(buf, msg->period); 401 _SHR_PACK_U32(buf, msg->loss_threshold); 402 _SHR_PACK_U32(buf, msg->loss_nearend); 403 _SHR_PACK_U32(buf, msg->tx_nearend); 404 _SHR_PACK_U32(buf, msg->rx_nearend); 405 _SHR_PACK_U32(buf, msg->tx_farend); 406 _SHR_PACK_U32(buf, msg->rx_farend); 407 _SHR_PACK_U32(buf, msg->rx_oam_packets); 408 _SHR_PACK_U32(buf, msg->tx_oam_packets); 409 _SHR_PACK_U32(buf, msg->int_pri); 410 _SHR_PACK_U8 (buf, msg->pkt_pri); 411 412 return buf; 413 } 414 415 uint8 * 416 shr_bhh_msg_ctrl_loss_get_unpack(uint8 *buf, 417 shr_bhh_msg_ctrl_loss_get_t *msg) 418 { 419 _SHR_UNPACK_U32(buf, msg->flags); 420 _SHR_UNPACK_U32(buf, msg->sess_id); 421 _SHR_UNPACK_U32(buf, msg->period); 422 _SHR_UNPACK_U32(buf, msg->loss_threshold); 423 _SHR_UNPACK_U32(buf, msg->loss_nearend); 424 _SHR_UNPACK_U32(buf, msg->tx_nearend); 425 _SHR_UNPACK_U32(buf, msg->rx_nearend); 426 _SHR_UNPACK_U32(buf, msg->tx_farend); 427 _SHR_UNPACK_U32(buf, msg->rx_farend); 428 _SHR_UNPACK_U32(buf, msg->rx_oam_packets); 429 _SHR_UNPACK_U32(buf, msg->tx_oam_packets); 430 _SHR_UNPACK_U32(buf, msg->int_pri); 431 _SHR_UNPACK_U8 (buf, msg->pkt_pri); 432 433 return buf; 434 } 435 436 uint8 * 437 shr_bhh_msg_ctrl_delay_add_pack(uint8 *buf, 438 shr_bhh_msg_ctrl_delay_add_t *msg) 439 { 440 _SHR_PACK_U32(buf, msg->flags); 441 _SHR_PACK_U32(buf, msg->sess_id); 442 _SHR_PACK_U32(buf, msg->period); 443 _SHR_PACK_U32(buf, msg->int_pri); 444 _SHR_PACK_U8 (buf, msg->pkt_pri); 445 _SHR_PACK_U8 (buf, msg->dm_format); 446 447 return buf; 448 } 449 450 uint8 * 451 shr_bhh_msg_ctrl_delay_add_unpack(uint8 *buf, 452 shr_bhh_msg_ctrl_delay_add_t *msg) 453 { 454 _SHR_UNPACK_U32(buf, msg->flags); 455 _SHR_UNPACK_U32(buf, msg->sess_id); 456 _SHR_UNPACK_U32(buf, msg->period); 457 _SHR_UNPACK_U32(buf, msg->int_pri); 458 _SHR_UNPACK_U8 (buf, msg->pkt_pri); 459 _SHR_UNPACK_U8 (buf, msg->dm_format); 460 461 return buf; 462 } 463 464 uint8 * 465 shr_bhh_msg_ctrl_delay_delete_pack(uint8 *buf, 466 shr_bhh_msg_ctrl_delay_delete_t *msg) 467 { 468 _SHR_PACK_U32(buf, msg->sess_id); 469 470 return buf; 471 } 472 473 uint8 * 474 shr_bhh_msg_ctrl_delay_delete_unpack(uint8 *buf, 475 shr_bhh_msg_ctrl_delay_delete_t *msg) 476 { 477 _SHR_UNPACK_U32(buf, msg->sess_id); 478 479 return buf; 480 } 481 482 uint8 * 483 shr_bhh_msg_ctrl_delay_get_pack(uint8 *buf, 484 shr_bhh_msg_ctrl_delay_get_t *msg) 485 { 486 487 _SHR_PACK_U32(buf, msg->flags); 488 _SHR_PACK_U32(buf, msg->sess_id); 489 _SHR_PACK_U32(buf, msg->period); 490 _SHR_PACK_U32(buf, msg->delay_seconds); 491 _SHR_PACK_U32(buf, msg->delay_nanoseconds); 492 _SHR_PACK_U32(buf, msg->txf_seconds); 493 _SHR_PACK_U32(buf, msg->txf_nanoseconds); 494 _SHR_PACK_U32(buf, msg->rxf_seconds); 495 _SHR_PACK_U32(buf, msg->rxf_nanoseconds); 496 _SHR_PACK_U32(buf, msg->txb_seconds); 497 _SHR_PACK_U32(buf, msg->txb_nanoseconds); 498 _SHR_PACK_U32(buf, msg->rxb_seconds); 499 _SHR_PACK_U32(buf, msg->rxb_nanoseconds); 500 _SHR_PACK_U32(buf, msg->rx_oam_packets); 501 _SHR_PACK_U32(buf, msg->tx_oam_packets); 502 _SHR_PACK_U32(buf, msg->int_pri); 503 _SHR_PACK_U8 (buf, msg->pkt_pri); 504 _SHR_PACK_U8 (buf, msg->dm_format); 505 506 return buf; 507 } 508 509 uint8 * 510 shr_bhh_msg_ctrl_delay_get_unpack(uint8 *buf, 511 shr_bhh_msg_ctrl_delay_get_t *msg) 512 { 513 514 _SHR_UNPACK_U32(buf, msg->flags); 515 _SHR_UNPACK_U32(buf, msg->sess_id); 516 _SHR_UNPACK_U32(buf, msg->period); 517 _SHR_UNPACK_U32(buf, msg->delay_seconds); 518 _SHR_UNPACK_U32(buf, msg->delay_nanoseconds); 519 _SHR_UNPACK_U32(buf, msg->txf_seconds); 520 _SHR_UNPACK_U32(buf, msg->txf_nanoseconds); 521 _SHR_UNPACK_U32(buf, msg->rxf_seconds); 522 _SHR_UNPACK_U32(buf, msg->rxf_nanoseconds); 523 _SHR_UNPACK_U32(buf, msg->txb_seconds); 524 _SHR_UNPACK_U32(buf, msg->txb_nanoseconds); 525 _SHR_UNPACK_U32(buf, msg->rxb_seconds); 526 _SHR_UNPACK_U32(buf, msg->rxb_nanoseconds); 527 _SHR_UNPACK_U32(buf, msg->rx_oam_packets); 528 _SHR_UNPACK_U32(buf, msg->tx_oam_packets); 529 _SHR_UNPACK_U32(buf, msg->int_pri); 530 _SHR_UNPACK_U8 (buf, msg->pkt_pri); 531 _SHR_UNPACK_U8 (buf, msg->dm_format); 532 533 return buf; 534 } 535 536 /********************************************************* 537 * BHH Network Packet Header Pack/Unpack 538 * 539 * Functions: 540 * shr_bhh_<header>_pack/unpack 541 * Purpose: 542 * The following set of routines pack/unpack specified 543 * network packet header to/from given buffer. 544 * Parameters: 545 * _pack() 546 * buffer - (OUT) Buffer where to pack header. 547 * <header> - (IN) Header to pack. 548 * _unpack() 549 * buffer - (IN) Buffer with data to unpack. 550 * <header> - (OUT) Returns unpack header. 551 * Returns: 552 * Pointer to next position in buffer. 553 * Notes: 554 * Assumes pointers are valid and contain enough memory space. 555 */ 556 557 /********************************************************* 558 * BHH TLV Pack/Unpack 559 * 560 * Functions: 561 * 562 * Purpose: 563 * The following set of routines pack/unpack specified 564 * 565 * Parameters: 566 * _pack() 567 * buffer - (OUT) Buffer where to pack header. 568 * 569 * _unpack() 570 * buffer - (IN) Buffer with data to unpack. 571 * 572 * Returns: 573 * 574 * Notes: 575 */ 576 uint8 * 577 shr_bhh_tlv_pack(uint8 *buf, shr_bhh_tlv_t *tlv) 578 { 579 int i; 580 581 _SHR_PACK_U8(buf, tlv->type); 582 583 if (tlv->type == SHR_BHH_TLV_END) { 584 tlv->length = 0; 585 tlv->subtype = 0; 586 } else { 587 _SHR_PACK_U16(buf, tlv->length); 588 _SHR_PACK_U8(buf, tlv->subtype); 589 590 if (tlv->type == SHR_BHH_TLV_REQUESTING_MEP) { 591 _SHR_PACK_U16(buf, tlv->value.requesting.mep_id); 592 for (i = 0;i < sizeof(tlv->value.requesting.meg_id);i++) { 593 _SHR_PACK_U8(buf, tlv->value.requesting.meg_id[i]); 594 } 595 _SHR_PACK_U16(buf, 0x0000); 596 } else if (tlv->type == SHR_BHH_TLV_TARGET_MEP || 597 tlv->type == SHR_BHH_TLV_REPLYING_MEP) { 598 switch (tlv->subtype) { 599 case SHR_BHH_TLV_MEP_SUB_INGRESS_DISCOVERY: 600 case SHR_BHH_TLV_MEP_SUB_EGRESS_DISCOVERY: 601 for (i = 0;i < SHR_BHH_ID_ZERO_LEN;i++) { 602 _SHR_PACK_U8(buf, 0); 603 } 604 break; 605 606 case SHR_BHH_TLV_MEP_SUB_MEP_ICC_ID: 607 { 608 _SHR_PACK_U16(buf, tlv->value.reply_icc.mep_id); 609 for (i = 0;i < sizeof(tlv->value.reply_icc.zero);i++) { 610 _SHR_PACK_U8(buf, 0); 611 } 612 } 613 break; 614 615 case SHR_BHH_TLV_MEP_SUB_MIP_ICC_ID: 616 { 617 for (i = 0;i < sizeof(tlv->value.reply_mip_icc.carrier_code);i++) { 618 _SHR_PACK_U8(buf, tlv->value.reply_mip_icc.carrier_code[i]); 619 } 620 _SHR_PACK_U32(buf, tlv->value.reply_mip_icc.node_id); 621 _SHR_PACK_U32(buf, tlv->value.reply_mip_icc.if_num); 622 for (i = 0;i < sizeof(tlv->value.reply_mip_icc.zero);i++) { 623 _SHR_PACK_U8(buf, 0); 624 } 625 } 626 break; 627 } 628 } else { 629 ; 630 } 631 } 632 633 return buf; 634 } 635 636 637 638 uint8 * 639 shr_bhh_tlv_unpack(uint8 *buf, shr_bhh_tlv_t *tlv) 640 { 641 int i; 642 643 _SHR_UNPACK_U8(buf, tlv->type); 644 _SHR_UNPACK_U16(buf, tlv->length); 645 _SHR_UNPACK_U8(buf, tlv->subtype); 646 647 if (tlv->type == SHR_BHH_TLV_REQUESTING_MEP) { 648 _SHR_UNPACK_U16(buf, tlv->value.requesting.mep_id); 649 for (i = 0;i < sizeof(tlv->value.requesting.meg_id);i++) { 650 _SHR_UNPACK_U8(buf, tlv->value.requesting.meg_id[i]); 651 } 652 _SHR_UNPACK_U16(buf, tlv->value.requesting.reserved); 653 } else if (tlv->type == SHR_BHH_TLV_TARGET_MEP || 654 tlv->type == SHR_BHH_TLV_REPLYING_MEP) { 655 switch (tlv->subtype) { 656 case SHR_BHH_TLV_MEP_SUB_INGRESS_DISCOVERY: 657 case SHR_BHH_TLV_MEP_SUB_EGRESS_DISCOVERY: 658 { 659 for (i = 0;i < SHR_BHH_ID_ZERO_LEN;i++) { 660 _SHR_UNPACK_U8(buf, tlv->value.discovery.zero[i]); 661 } 662 } 663 break; 664 665 case SHR_BHH_TLV_MEP_SUB_MEP_ICC_ID: 666 { 667 _SHR_UNPACK_U16(buf, tlv->value.reply_icc.mep_id); 668 for (i = 0;i < sizeof(tlv->value.reply_icc.zero);i++) { 669 _SHR_UNPACK_U8(buf, tlv->value.reply_icc.zero[i]); 670 } 671 } 672 break; 673 674 case SHR_BHH_TLV_MEP_SUB_MIP_ICC_ID: 675 { 676 for (i = 0;i < sizeof(tlv->value.reply_mip_icc.carrier_code);i++) { 677 _SHR_UNPACK_U8(buf, tlv->value.reply_mip_icc.carrier_code[i]); 678 } 679 _SHR_UNPACK_U32(buf, tlv->value.reply_mip_icc.node_id); 680 _SHR_UNPACK_U32(buf, tlv->value.reply_mip_icc.if_num); 681 for (i = 0;i < sizeof(tlv->value.reply_mip_icc.zero);i++) { 682 _SHR_UNPACK_U8(buf, tlv->value.reply_mip_icc.zero[i]); 683 } 684 } 685 break; 686 } 687 } else { 688 ; 689 } 690 691 return buf; 692 } 693