# p2p_protocol.h

Go to the documentation of this file.

    00001 /* Copyright (c) 2007 - 2012 Axel Wachtler
    00002    All rights reserved.
    00003
    00004    Redistribution and use in source and binary forms, with or without
    00005    modification, are permitted provided that the following conditions
    00006    are met:
    00007
    00008    * Redistributions of source code must retain the above copyright
    00009      notice, this list of conditions and the following disclaimer.
    00010    * Redistributions in binary form must reproduce the above copyright
    00011      notice, this list of conditions and the following disclaimer in the
    00012      documentation and/or other materials provided with the distribution.
    00013    * Neither the name of the authors nor the names of its contributors
    00014      may be used to endorse or promote products derived from this software
    00015      without specific prior written permission.
    00016
    00017    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00018    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00019    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00020    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00021    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    00022    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    00023    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    00024    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    00025    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    00026    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    00027    POSSIBILITY OF SUCH DAMAGE. */
    00028
    00029 /* $Id$ */
    00036 #ifndef P2P_PROTOCOL_H
    00037 #define P2P_PROTOCOL_H
    00038
    00039 #include <stdint.h>
    00040
    00041 /* === Macros =============================================================== */
    00042
    00045 /* === generic commands ===================================================== */
    00046 #define P2P_PING_REQ (0x01)
    00048 #define P2P_PING_CNF (0x02)
    00049 #define P2P_JUMP_BOOTL (0x03)
    00051 /* === wibo ================================================================= */
    00052 #define P2P_WIBO_DATA (0x20)
    00053 #define P2P_WIBO_FINISH (0x21)
    00054 #define P2P_WIBO_RESET (0x22)
    00055 #define P2P_WIBO_EXIT (0x23)
    00057 /* === wibo example application ============================================= */
    00058 #define P2P_XMPL_LED (0x30)
    00060 /* === wuart ================================================================ */
    00061 #define P2P_WUART_DATA (0x40)
    00063 /* === chsweep ============================================================== */
    00064 #define P2P_CHSWEEP_SWEEP_REQ (0x50)
    00066 #define P2P_CHSWEEP_RESULT_REQ (0x51)
    00067 #define P2P_CHSWEEP_RESULT_CNF (0x52)
    00068 #define P2P_CHSWEEP_EXEC_REQ (0x53)
    00072 /* === Types ================================================================ */
    00073
    00074 typedef enum {
    00075     P2P_STATUS_IDLE = 0x00,
    00076     P2P_STATUS_RECEIVINGDATA = 0x01,
    00077     P2P_STATUS_ERROR = 0xFF
    00078 } p2p_status_t;
    00079
    00080 typedef enum {
    00081     P2P_ERROR_NONE = 0x00,
    00082     P2P_ERROR_NONE_DATAMISS,
    00083     P2P_ERROR_SUCCESS
    00084 } p2p_error_t;
    00085
    00091 typedef struct
    00092 {
    00093     uint16_t fcf;
    00094     uint8_t  seq;
    00095     uint16_t pan;
    00096     uint16_t dst;
    00097     uint16_t src;
    00098     uint8_t cmd;
    00100 } p2p_hdr_t;
    00101
    00102 #define __FILL_P2P_HEADER__(hdr, vfcf, vpan, vdst, vsrc, vcmd) \
    00103     do{\
    00104         hdr->fcf = (vfcf);\
    00105         hdr->seq += 1;\
    00106         hdr->pan = (vpan);\
    00107         hdr->dst = (vdst);\
    00108         hdr->src = (vsrc);\
    00109         hdr->cmd = (vcmd);\
    00110     }while(0)
    00111
    00113 #define FILL_P2P_HEADER_ACK(hdr, pan, dst, src, cmd) \
    00114          __FILL_P2P_HEADER__(hdr, 0x8861, pan, dst, src, cmd)
    00115
    00117 #define FILL_P2P_HEADER_NOACK(hdr, pan, dst, src, cmd) \
    00118          __FILL_P2P_HEADER__(hdr, 0x8841, pan, dst, src, cmd)
    00119
    00120 #define SET_P2P_HEADER_DESTADD(hdr, seq) \
    00121         do {hdr->dst = dst;} while(0)
    00122
    00123 #define INC_P2P_HEADER_SEQNB(hdr, seq) \
    00124         do {hdr->seq ++;} while(0)
    00125
    00126 #define SET_P2P_HEADER_SEQNB(hdr, seq) \
    00127         do {hdr->seq = (seq);} while(0)
    00128
    00129
    00131 typedef struct
    00132 {
    00133     p2p_hdr_t hdr;
    00134 } p2p_ping_req_t;
    00135
    00136
    00138 typedef struct
    00139 {
    00140     p2p_hdr_t hdr;
    00141     p2p_status_t status;
    00142     p2p_error_t errno;
    00143     uint8_t version;
    00144     uint16_t crc;
    00145     uint16_t pagesize;
    00146     char appname[8];
    00147     char boardname[];
    00148 } p2p_ping_cnf_t;
    00149
    00151 typedef struct
    00152 {
    00153     p2p_hdr_t hdr;
    00154 } p2p_jump_bootl_t;
    00155
    00157 typedef struct {
    00158     p2p_hdr_t hdr;
    00159     uint8_t targmem;
    00160     uint8_t dsize;
    00161     uint8_t data[];
    00162 } p2p_wibo_data_t;
    00163
    00165 typedef struct
    00166 {
    00167     p2p_hdr_t hdr;
    00168 } p2p_wibo_finish_t;
    00169
    00170
    00172 typedef struct
    00173 {
    00174     p2p_hdr_t hdr;
    00175 } p2p_wibo_reset_t;
    00176
    00178 typedef struct
    00179 {
    00180     p2p_hdr_t hdr;
    00181 } p2p_wibo_exit_t;
    00182
    00184 typedef struct {
    00185     p2p_hdr_t hdr;
    00186     uint8_t led;
    00187     uint8_t state;
    00188 } p2p_xmpl_led_t;
    00189
    00191 typedef struct
    00192 {
    00193     p2p_hdr_t hdr;
    00194     uint8_t mode;
    00195 } p2p_wuart_data_t;
    00196
    00198 typedef struct{
    00199     p2p_hdr_t hdr;
    00200     uint16_t rx_addr;
    00201 } p2p_chsweep_sweep_req_t;
    00202
    00204 typedef struct {
    00205     p2p_hdr_t hdr;
    00206     uint8_t res_mode;
    00207 } p2p_chsweep_result_req_t;
    00208
    00210 typedef struct
    00211 {
    00212     p2p_hdr_t hdr;
    00213     uint8_t res_mode;
    00214     uint8_t data[];
    00215 } p2p_chsweep_result_cnf_t;
    00216
    00218 typedef struct
    00219 {
    00220     p2p_hdr_t hdr;
    00221     uint8_t clear_stat;
    00222     uint8_t next_channel;
    00223 } p2p_chsweep_exec_req_t;
    00224
    00225 /* === prototypes ========================================================== */
    00226 #ifdef __cplusplus
    00227 extern "C" {
    00228 #endif
    00229
    00230 #ifdef __cplusplus
    00231 } /* extern "C" */
    00232 #endif
    00233
    00234
    00235 #endif /* ifndef P2P_PROTOCOL_H */