-
Notifications
You must be signed in to change notification settings - Fork 11
/
packet.h
98 lines (80 loc) · 2.41 KB
/
packet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#ifndef PACKET_H
#define PACKET_H
#include <linux/types.h>
typedef u16 ieee154_addr_t;
typedef u16 ieee154_panid_t;
typedef struct cc2520_header_t
{
u8 length;
}__attribute__((packed)) cc2520_header_t;
typedef struct ieee154_simple_header_t
{
u16 fcf;
u8 dsn;
u16 destpan;
u16 dest;
u16 src;
}__attribute__((packed)) ieee154_simple_header_t;
typedef struct cc2520packet_header_t
{
cc2520_header_t cc2520;
ieee154_simple_header_t ieee154;
}__attribute__((packed)) cc2520packet_header_t;
enum {
IEEE154_BROADCAST_ADDR = 0xffff,
IEEE154_BROADCAST_PAN = 0xffff,
IEEE154_LINK_MTU = 127,
};
struct ieee154_frame_addr {
ieee154_addr_t ieee_src;
ieee154_addr_t ieee_dst;
ieee154_panid_t ieee_dstpan;
}__attribute__((packed));
enum ieee154_fcf_enums {
IEEE154_FCF_FRAME_TYPE = 0,
IEEE154_FCF_SECURITY_ENABLED = 3,
IEEE154_FCF_FRAME_PENDING = 4,
IEEE154_FCF_ACK_REQ = 5,
IEEE154_FCF_INTRAPAN = 6,
IEEE154_FCF_DEST_ADDR_MODE = 10,
IEEE154_FCF_SRC_ADDR_MODE = 14,
};
enum ieee154_fcf_type_enums {
IEEE154_TYPE_BEACON = 0,
IEEE154_TYPE_DATA = 1,
IEEE154_TYPE_ACK = 2,
IEEE154_TYPE_MAC_CMD = 3,
IEEE154_TYPE_MASK = 7,
};
enum ieee154_fcf_addr_mode_enums {
IEEE154_ADDR_NONE = 0,
IEEE154_ADDR_SHORT = 2,
IEEE154_ADDR_EXT = 3,
IEEE154_ADDR_MASK = 3,
};
enum
{
IEEE154_DATA_FRAME_MASK = (IEEE154_TYPE_MASK << IEEE154_FCF_FRAME_TYPE)
| (1 << IEEE154_FCF_INTRAPAN)
| (IEEE154_ADDR_MASK << IEEE154_FCF_DEST_ADDR_MODE)
| (IEEE154_ADDR_MASK << IEEE154_FCF_SRC_ADDR_MODE),
IEEE154_DATA_FRAME_VALUE = (IEEE154_TYPE_DATA << IEEE154_FCF_FRAME_TYPE)
| (1 << IEEE154_FCF_INTRAPAN)
| (IEEE154_ADDR_SHORT << IEEE154_FCF_DEST_ADDR_MODE)
| (IEEE154_ADDR_SHORT << IEEE154_FCF_SRC_ADDR_MODE),
IEEE154_DATA_FRAME_PRESERVE = (1 << IEEE154_FCF_ACK_REQ)
| (1 << IEEE154_FCF_FRAME_PENDING),
IEEE154_ACK_FRAME_LENGTH = 5, // includes the FCF, DSN, FCS
IEEE154_ACK_FRAME_MASK = (IEEE154_TYPE_MASK << IEEE154_FCF_FRAME_TYPE),
IEEE154_ACK_FRAME_VALUE = (IEEE154_TYPE_ACK << IEEE154_FCF_FRAME_TYPE),
};
ieee154_simple_header_t* cc2520_packet_get_header(u8 *buf);
u8* cc2520_packet_get_length_field(u8 * buf);
u8* cc2520_packet_get_payload(u8 * buf);
bool cc2520_packet_requires_ack_reply(u8 *buf);
bool cc2520_packet_requires_ack_wait(u8 *buf);
void cc2520_packet_create_ack(u8 *pkt, u8 *buf);
bool cc2520_packet_is_ack(u8* buf);
bool cc2520_packet_is_ack_to(u8* pending, u8 * buf);
u64 cc2520_packet_get_src(u8 *buf);
#endif