From 8a068f8512f84bc718e764225c09892452241dc1 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Fri, 6 Dec 2013 11:25:23 +0000 Subject: [PATCH] Cleaned up linuxradiodrv code --- cpu/native/net/linuxradio-drv.c | 64 ++++++++++++++++++++++----------- cpu/native/net/linuxradio-drv.h | 35 ++++++++++++++++++ 2 files changed, 79 insertions(+), 20 deletions(-) diff --git a/cpu/native/net/linuxradio-drv.c b/cpu/native/net/linuxradio-drv.c index aa94e9e08..f0f254536 100644 --- a/cpu/native/net/linuxradio-drv.c +++ b/cpu/native/net/linuxradio-drv.c @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2013, Google + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Vladimir Pouzanov + * + */ + #include "contiki.h" #include "linuxradio-drv.h" @@ -26,27 +61,19 @@ static int sockfd = -1; static char *sockbuf; static int buflen; -#if 0 -static void my_memmove(char *s1, char *s2, int len) -{ - int i; - for(i=0; i 256) { + if (payload_len > MAX_PACKET_SIZE) { return 0; } memcpy(sockbuf, payload, payload_len); @@ -60,8 +87,8 @@ transmit(unsigned short transmit_len) { int sent=0; sent = send(sockfd, sockbuf, buflen, 0); - if(sent < 0) { - perror ("linuxradio send()"); + if (sent < 0) { + perror("linuxradio send()"); } buflen = 0; return RADIO_TX_OK; @@ -72,9 +99,7 @@ my_send(const void *payload, unsigned short payload_len) { int ret = -1; - PRINTF("PREPARE & TRANSMIT %u bytes\n", payload_len); - - if(prepare(payload, payload_len)) { + if (prepare(payload, payload_len)) { return ret; } @@ -117,10 +142,9 @@ set_fd(fd_set *rset, fd_set *wset) static void handle_fd(fd_set *rset, fd_set *wset) { - if(FD_ISSET(sockfd, rset)) { + if (FD_ISSET(sockfd, rset)) { int bytes = read(sockfd, sockbuf, 256); buflen = bytes; - PRINTF("linuxradio: read %d bytes\n", bytes); memcpy(packetbuf_dataptr(), sockbuf, bytes); packetbuf_set_datalen(bytes); NETSTACK_RDC.input(); @@ -133,7 +157,7 @@ static int on(void) { sockfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IEEE802154)); - if(sockfd < 0) { + if (sockfd < 0) { perror ("linuxradio socket()"); return 0; } else { @@ -146,7 +170,7 @@ on(void) sll.sll_ifindex = ifr.ifr_ifindex; sll.sll_protocol = htons(ETH_P_IEEE802154); - if(bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { + if (bind(sockfd, (struct sockaddr *)&sll, sizeof(sll)) < 0) { perror("linuxradio bind()"); return 0; } diff --git a/cpu/native/net/linuxradio-drv.h b/cpu/native/net/linuxradio-drv.h index 5952a3eb2..fddf38d01 100644 --- a/cpu/native/net/linuxradio-drv.h +++ b/cpu/native/net/linuxradio-drv.h @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2013, Google + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Author: Vladimir Pouzanov + * + */ + #ifndef __LINUXRADIO_DRV_H__ #define __LINUXRADIO_DRV_H__