fix some carriage return
[protos/xbee-avr.git] / xbee_proto.h
1 /*
2  * Copyright (c) 2011, Olivier MATZ <zer0@droids-corp.org>
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the University of California, Berkeley nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 /* protocol headers */
29
30 #define XBEE_DELIMITER 0x7E
31 #define XBEE_MAX_FRAME_LEN 0x200
32
33 struct xbee_hdr {
34         uint8_t delimiter;
35         uint16_t len;
36         uint8_t type;
37         uint8_t id;
38 } __attribute__((packed));
39
40 #define XBEE_TYPE_ATCMD 0x08
41 struct xbee_atcmd_hdr {
42         uint16_t cmd;
43         uint8_t params[];
44 } __attribute__((packed));
45
46 #define XBEE_TYPE_ATCMD_Q 0x09
47 struct xbee_atcmd_q_hdr {
48         uint16_t cmd;
49         uint8_t params[];
50 } __attribute__((packed));
51
52 #define XBEE_TYPE_XMIT 0x10
53 struct xbee_xmit_hdr {
54         uint64_t dstaddr;
55         uint16_t reserved;
56         uint8_t bcast_radius;
57         uint8_t opts;
58         uint8_t data[];
59 } __attribute__((packed));
60
61 #define XBEE_TYPE_EXPL_XMIT 0x11
62 struct xbee_expl_xmit_hdr {
63         uint64_t dstaddr;
64         uint16_t reserved;
65         uint8_t src_endpoint;
66         uint8_t dst_endpoint;
67         uint16_t cluster_id;
68         uint16_t profile_id;
69         uint8_t bcast_radius;
70         uint8_t opts;
71         uint8_t data[];
72 } __attribute__((packed));
73
74 #define XBEE_TYPE_RMT_ATCMD 0x17
75 struct xbee_rmt_atcmd_hdr {
76         uint64_t dstaddr;
77         uint16_t reserved;
78         uint8_t opts;
79         uint16_t cmd;
80         uint8_t params[];
81 } __attribute__((packed));
82
83 #define XBEE_TYPE_ATRESP 0x88
84 struct xbee_atresp_hdr {
85         uint16_t cmd;
86         uint8_t status;
87         uint8_t data[];
88 } __attribute__((packed));
89
90 #define XBEE_TYPE_MODEM_STATUS 0x8A
91 struct xbee_modem_status_hdr {
92         /* empty */
93 } __attribute__((packed));
94
95 #define XBEE_TYPE_XMIT_STATUS 0x8B
96 struct xbee_xmit_status_hdr {
97         uint16_t reserved;
98         uint8_t xmit_retry_cnt;
99         uint8_t delivery_status;
100         uint8_t discovery_status;
101 } __attribute__((packed));
102
103 #define XBEE_TYPE_RECV 0x90
104 struct xbee_recv_hdr {
105         uint64_t srcaddr;
106         uint16_t reserved;
107         uint8_t opts;
108         uint8_t data[];
109 } __attribute__((packed));
110
111 #define XBEE_TYPE_EXPL_RECV 0x91
112 struct xbee_expl_recv_hdr {
113         uint64_t srcaddr;
114         uint16_t reserved;
115         uint8_t src_endpoint;
116         uint8_t dst_endpoint;
117         uint16_t cluster_id;
118         uint16_t profile_id;
119         uint8_t opts;
120         uint8_t data[];
121 } __attribute__((packed));
122
123 #define XBEE_TYPE_NODE_ID 0x95
124 struct xbee_node_id_hdr {
125         uint64_t srcaddr;
126         uint16_t srcnetwork;
127         uint8_t opts;
128         uint16_t dstnetwork;
129         uint64_t dstaddr;
130         uint8_t ni_string[];
131         /* uint16_t parentaddr; after variable field */
132 } __attribute__((packed));
133
134 #define XBEE_TYPE_RMT_ATRESP 0x97
135 struct xbee_rmt_atresp_hdr {
136         uint64_t srcaddr;
137         uint16_t reserved;
138         uint16_t cmd;
139         uint8_t status;
140         uint8_t data[];
141 } __attribute__((packed));
142
143 struct xbee_dev;
144
145 /* return negative on error, 0 if there is not frame, or framelen */
146 int xbee_proto_get_frame(struct xbee_dev *dev, void *buf, unsigned len);
147
148 /* send a frame */
149 int xbee_proto_xmit(struct xbee_dev *dev, uint8_t id, uint8_t type,
150                     void *buf, unsigned len);
151
152 void xbee_proto_rx(struct xbee_dev *dev);