Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2009, Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. 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 * 3. Neither the name of the Institute 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 INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * 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 INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * $Id: framer-nullmac.c,v 1.2 2010/06/14 19:19:16 adamdunkels Exp $ 00030 */ 00031 00032 /** 00033 * \file 00034 * MAC framer for nullmac 00035 * \author 00036 * Niclas Finne <nfi@sics.se> 00037 * Joakim Eriksson <joakime@sics.se> 00038 */ 00039 00040 #include "net/mac/framer-nullmac.h" 00041 #include "net/packetbuf.h" 00042 00043 #define DEBUG 0 00044 00045 #if DEBUG 00046 #include <stdio.h> 00047 #define PRINTF(...) printf(__VA_ARGS__) 00048 #define PRINTADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7]) 00049 #else 00050 #define PRINTF(...) 00051 #define PRINTADDR(addr) 00052 #endif 00053 00054 struct nullmac_hdr { 00055 rimeaddr_t receiver; 00056 rimeaddr_t sender; 00057 }; 00058 00059 /*---------------------------------------------------------------------------*/ 00060 static int 00061 create(void) 00062 { 00063 struct nullmac_hdr *hdr; 00064 00065 if(packetbuf_hdralloc(sizeof(struct nullmac_hdr))) { 00066 hdr = packetbuf_hdrptr(); 00067 rimeaddr_copy(&(hdr->sender), &rimeaddr_node_addr); 00068 rimeaddr_copy(&(hdr->receiver), packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); 00069 return sizeof(struct nullmac_hdr); 00070 } 00071 PRINTF("PNULLMAC-UT: too large header: %u\n", len); 00072 return FRAMER_FAILED; 00073 } 00074 /*---------------------------------------------------------------------------*/ 00075 static int 00076 parse(void) 00077 { 00078 struct nullmac_hdr *hdr; 00079 hdr = packetbuf_dataptr(); 00080 if(packetbuf_hdrreduce(sizeof(struct nullmac_hdr))) { 00081 packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &(hdr->sender)); 00082 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &(hdr->receiver)); 00083 00084 PRINTF("PNULLMAC-IN: "); 00085 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); 00086 PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER)); 00087 PRINTF("%u (%u)\n", packetbuf_datalen(), len); 00088 00089 return sizeof(struct nullmac_hdr); 00090 } 00091 return FRAMER_FAILED; 00092 } 00093 /*---------------------------------------------------------------------------*/ 00094 const struct framer framer_nullmac = { 00095 create, parse 00096 };