1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /* IP Header */ 22 typedef struct Ipv4Hdr { 23 uint8_t ver_hl; /* version/header length */ 24 uint8_t tos; /* type of service */ 25 uint16_t length; /* total length */ 26 uint16_t id; /* identification */ 27 uint16_t offset; /* fragment offset field */ 28 uint8_t ttl; /* time to live */ 29 uint8_t protocol; /* protocol */ 30 uint16_t sum; /* checksum */ 31 uint32_t src; /* source address */ 32 uint32_t dst; /* destination address */ 33 } Ipv4Hdr; 34 35 36 /* TCP Header */ 37 typedef struct TcpHdr { 38 uint16_t srcPort; /* source port */ 39 uint16_t dstPort; /* destination port */ 40 uint32_t sequence; /* sequence number */ 41 uint32_t ack; /* acknoledgment number */ 42 uint8_t offset; /* data offset, reserved */ 43 uint8_t flags; /* option flags */ 44 uint16_t window; /* window */ 45 uint16_t sum; /* checksum */ 46 uint16_t urgent; /* urgent pointer */ 47 } TcpHdr; 48 49 /* UDP Header */ 50 typedef struct UdpHdr { 51 uint16_t srcPort; /* source port */ 52 uint16_t dstPort; /* destination port */ 53 uint16_t len; /* len */ 54 uint16_t sum; /* checksum */ 55 } UdpHdr; 56 57 void MQTTPacket_header_parse(uint32_t buf,uint16_t packet_len); 58 59 #define TX_PER_PACKET_INFO_OUTPUT (1<<0) 60 #define TX_PAYLOAD_PARSE (1<<1) 61 #define TX_MQTT_PACKET_HEADER_PARSE (1<<2) 62 63 #define RX_PER_PACKET_INFO_OUTPUT (1<<3) 64 #define RX_PAYLOAD_PARSE (1<<4) 65 #define RX_MQTT_PACKET_HEADER_PARSE (1<<5) 66 67 #define PACKET_TYPE_BASE (8) 68 69 #define PACKET_TYPE_MGT (1<<PACKET_TYPE_BASE) 70 #define PACKET_TYPE_CTRL (1<<(PACKET_TYPE_BASE+1)) 71 #define PACKET_TYPE_DATA (1<<(PACKET_TYPE_BASE+2)) 72 73 #define PACKET_AC_BASE (12) 74 75 #define PACKET_AC_BK (1<<PACKET_AC_BASE) 76 #define PACKET_AC_BE (1<<(PACKET_AC_BASE+1)) 77 #define PACKET_AC_VI (1<<(PACKET_AC_BASE+2)) 78 #define PACKET_AC_VO (1<<(PACKET_AC_BASE+3)) 79 80 extern uint32_t g_per_packet_info_output_bitmap; 81 82 #ifdef __cplusplus 83 } 84 #endif 85