Added support for socket descriptors

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@318 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2007-09-01 18:06:15 +00:00
parent c60f939f91
commit 29aeec7b8a
44 changed files with 1900 additions and 1205 deletions
+3 -3
View File
@@ -37,9 +37,9 @@
MKDEP = $(TOPDIR)/tools/mkdeps.sh
ifeq ($(CONFIG_NET_UIP),y)
ifeq ($(CONFIG_NET),y)
STD_ASRCS =
STD_CSRCS = socket.c bind.c
STD_CSRCS = socket.c bind.c net_sockets.c
include uip/Make.defs
endif
@@ -71,7 +71,7 @@ $(BIN): $(OBJS)
done ; )
.depend: Makefile $(SRCS)
ifeq ($(CONFIG_NET_UIP),y)
ifeq ($(CONFIG_NET),y)
$(MKDEP) --dep-path . --dep-path uip $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
endif
touch $@
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* net_internal.h
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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 Gregory Nutt 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 COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*
****************************************************************************/
#ifndef __NET_INTERNAL_H
#define __NET_INTERNAL_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_NET
#include <nuttx/net.h>
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Variables
****************************************************************************/
/****************************************************************************
* Pulblic Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/* net_sockets.c *************************************************************/
EXTERN void weak_function net_initialize(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* CONFIG_NET */
#endif /* __NET_INTERNAL_H */
+171
View File
@@ -0,0 +1,171 @@
/****************************************************************************
* net_sockets.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* 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 Gregory Nutt 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 COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <semaphore.h>
#include <assert.h>
#include <sched.h>
#include <errno.h>
#include <nuttx/net.h>
#include <nuttx/kmalloc.h>
#include "net_internal.h"
/****************************************************************************
* Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Variables
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
static void _net_semtake(FAR struct socketlist *list)
{
/* Take the semaphore (perhaps waiting) */
while (sem_wait(&list->sl_sem) != 0)
{
/* The only case that an error should occr here is if
* the wait was awakened by a signal.
*/
ASSERT(*get_errno_ptr() == EINTR);
}
}
#define _net_semgive(list) sem_post(&list->sl_sem)
/****************************************************************************
* Pulblic Functions
****************************************************************************/
/* This is called from the initialization logic to configure the socket layer */
void net_initialize(void)
{
}
/* Allocate a list of files for a new task */
FAR struct socketlist *net_alloclist(void)
{
FAR struct socketlist *list;
list = (FAR struct socketlist*)kzmalloc(sizeof(struct socketlist));
if (list)
{
/* Start with a reference count of one */
list->sl_crefs = 1;
/* Initialize the list access mutex */
(void)sem_init(&list->sl_sem, 0, 1);
}
return list;
}
/* Increase the reference count on a file list */
int net_addreflist(FAR struct socketlist *list)
{
if (list)
{
/* Increment the reference count on the list.
* NOTE: that we disable interrupts to do this
* (vs. taking the list semaphore). We do this
* because file cleanup operations often must be
* done from the IDLE task which cannot wait
* on semaphores.
*/
register irqstate_t flags = irqsave();
list->sl_crefs++;
irqrestore(flags);
}
return OK;
}
/* Release a reference to the file list */
int net_releaselist(FAR struct socketlist *list)
{
int crefs;
if (list)
{
/* Decrement the reference count on the list.
* NOTE: that we disable interrupts to do this
* (vs. taking the list semaphore). We do this
* because file cleanup operations often must be
* done from the IDLE task which cannot wait
* on semaphores.
*/
irqstate_t flags = irqsave();
crefs = --(list->sl_crefs);
irqrestore(flags);
/* If the count decrements to zero, then there is no reference
* to the structure and it should be deallocated. Since there
* are references, it would be an error if any task still held
* a reference to the list's semaphore.
*/
if (crefs <= 0)
{
/* Destroy the semaphore and release the filelist */
(void)sem_destroy(&list->sl_sem);
sched_free(list);
}
}
return OK;
}
+2 -1
View File
@@ -30,7 +30,7 @@
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: psock.c,v 1.1.1.1 2007-08-26 23:04:11 patacongo Exp $
* $Id: psock.c,v 1.2 2007-09-01 18:06:13 patacongo Exp $
*/
#include <stdio.h>
@@ -375,3 +375,4 @@ void psock_init(register struct psock *psock, char *buffer, unsigned int buffers
psock->bufsize = buffersize;
buf_setup(&psock->buf, (uint8*)buffer, buffersize);
}
+2 -2
View File
@@ -136,8 +136,8 @@ struct fwcache_entry {
/*
* The number of packets to remember when looking for duplicates.
*/
#ifdef CONFIG_UIP_FWCACHE_SIZE
# define FWCACHE_SIZE CONFIG_UIP_FWCACHE_SIZE
#ifdef CONFIG_NET_FWCACHE_SIZE
# define FWCACHE_SIZE CONFIG_NET_FWCACHE_SIZE
#else
# define FWCACHE_SIZE 2
#endif
+76 -75
View File
@@ -1,6 +1,11 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
* uip-neighbor.c
* Database of link-local neighbors, used by IPv6 code and to be used by
* a future ARP code rewrite.
*
* Author: Adam Dunkels <adam@sics.se>
* Copyright (c) 2006, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,23 +30,12 @@
* 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.
*
* This file is part of the uIP TCP/IP stack
*
* $Id: uip-neighbor.c,v 1.1.1.1 2007-08-26 23:04:08 patacongo Exp $
*/
/**
* \file
* Database of link-local neighbors, used by IPv6 code and
* to be used by a future ARP code rewrite.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "uip-neighbor.h"
#include <string.h>
#include <debug.h>
#define MAX_TIME 128
@@ -51,108 +45,115 @@
#define ENTRIES 8
#endif /* UIP_NEIGHBOR_CONF_ENTRIES */
struct neighbor_entry {
struct neighbor_entry
{
uip_ipaddr_t ipaddr;
struct uip_neighbor_addr addr;
uint8 time;
};
static struct neighbor_entry entries[ENTRIES];
/*---------------------------------------------------------------------------*/
void
uip_neighbor_init(void)
void uip_neighbor_init(void)
{
int i;
for(i = 0; i < ENTRIES; ++i) {
entries[i].time = MAX_TIME;
}
}
/*---------------------------------------------------------------------------*/
void
uip_neighbor_periodic(void)
{
int i;
for(i = 0; i < ENTRIES; ++i) {
if(entries[i].time < MAX_TIME) {
entries[i].time++;
for(i = 0; i < ENTRIES; ++i)
{
entries[i].time = MAX_TIME;
}
}
}
/*---------------------------------------------------------------------------*/
void
uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
void uip_neighbor_periodic(void)
{
int i;
for(i = 0; i < ENTRIES; ++i)
{
if (entries[i].time < MAX_TIME)
{
entries[i].time++;
}
}
}
void uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
{
int i, oldest;
uint8 oldest_time;
printf("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
addr->addr.addr[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3],
addr->addr.addr[4], addr->addr.addr[5]);
dbg("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
addr->addr.addr[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3],
addr->addr.addr[4], addr->addr.addr[5]);
/* Find the first unused entry or the oldest used entry. */
oldest_time = 0;
oldest = 0;
for(i = 0; i < ENTRIES; ++i) {
if(entries[i].time == MAX_TIME) {
oldest = i;
break;
for (i = 0; i < ENTRIES; ++i)
{
if (entries[i].time == MAX_TIME)
{
oldest = i;
break;
}
if (uip_ipaddr_cmp(entries[i].ipaddr, addr))
{
oldest = i;
break;
}
if (entries[i].time > oldest_time)
{
oldest = i;
oldest_time = entries[i].time;
}
}
if(uip_ipaddr_cmp(entries[i].ipaddr, addr)) {
oldest = i;
break;
}
if(entries[i].time > oldest_time) {
oldest = i;
oldest_time = entries[i].time;
}
}
/* Use the oldest or first free entry (either pointed to by the
"oldest" variable). */
* "oldest" variable).
*/
entries[oldest].time = 0;
uip_ipaddr_copy(entries[oldest].ipaddr, ipaddr);
memcpy(&entries[oldest].addr, addr, sizeof(struct uip_neighbor_addr));
}
/*---------------------------------------------------------------------------*/
static struct neighbor_entry *
find_entry(uip_ipaddr_t ipaddr)
static struct neighbor_entry *find_entry(uip_ipaddr_t ipaddr)
{
int i;
for(i = 0; i < ENTRIES; ++i) {
if(uip_ipaddr_cmp(entries[i].ipaddr, ipaddr)) {
return &entries[i];
for(i = 0; i < ENTRIES; ++i)
{
if (uip_ipaddr_cmp(entries[i].ipaddr, ipaddr))
{
return &entries[i];
}
}
}
return NULL;
}
/*---------------------------------------------------------------------------*/
void
uip_neighbor_update(uip_ipaddr_t ipaddr)
void uip_neighbor_update(uip_ipaddr_t ipaddr)
{
struct neighbor_entry *e;
e = find_entry(ipaddr);
if(e != NULL) {
e->time = 0;
}
if (e != NULL)
{
e->time = 0;
}
}
/*---------------------------------------------------------------------------*/
struct uip_neighbor_addr *
uip_neighbor_lookup(uip_ipaddr_t ipaddr)
struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t ipaddr)
{
struct neighbor_entry *e;
e = find_entry(ipaddr);
if(e != NULL) {
/* printf("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3],
e->addr.addr.addr[4], e->addr.addr.addr[5]);*/
if (e != NULL)
{
dbg("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3],
e->addr.addr.addr[4], e->addr.addr.addr[5]);
return &e->addr;
}
return NULL;
}
/*---------------------------------------------------------------------------*/
+10 -10
View File
@@ -61,25 +61,25 @@ uip_split_output(void)
/* Create the first packet. This is done by altering the length
field of the IP header and updating the checksums. */
uip_len = len1 + UIP_TCPIP_HLEN;
#ifdef CONFIG_NET_UIP_IPv6
#ifdef CONFIG_NET_IPv6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
#else /* CONFIG_NET_UIP_IPv6 */
#else /* CONFIG_NET_IPv6 */
BUF->len[0] = uip_len >> 8;
BUF->len[1] = uip_len & 0xff;
#endif /* CONFIG_NET_UIP_IPv6 */
#endif /* CONFIG_NET_IPv6 */
/* Recalculate the TCP checksum. */
BUF->tcpchksum = 0;
BUF->tcpchksum = ~(uip_tcpchksum());
#ifndef CONFIG_NET_UIP_IPv6
#ifndef CONFIG_NET_IPv6
/* Recalculate the IP checksum. */
BUF->ipchksum = 0;
BUF->ipchksum = ~(uip_ipchksum());
#endif /* CONFIG_NET_UIP_IPv6 */
#endif /* CONFIG_NET_IPv6 */
/* Transmit the first packet. */
/* uip_fw_output();*/
@@ -91,15 +91,15 @@ uip_split_output(void)
memory. This place is detemined by the length of the first
packet (len1). */
uip_len = len2 + UIP_TCPIP_HLEN;
#ifdef CONFIG_NET_UIP_IPv6
#ifdef CONFIG_NET_IPv6
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
#else /* CONFIG_NET_UIP_IPv6 */
#else /* CONFIG_NET_IPv6 */
BUF->len[0] = uip_len >> 8;
BUF->len[1] = uip_len & 0xff;
#endif /* CONFIG_NET_UIP_IPv6 */
#endif /* CONFIG_NET_IPv6 */
/* uip_appdata += len1;*/
memcpy(uip_appdata, (uint8 *)uip_appdata + len1, len2);
@@ -114,11 +114,11 @@ uip_split_output(void)
BUF->tcpchksum = 0;
BUF->tcpchksum = ~(uip_tcpchksum());
#ifndef CONFIG_NET_UIP_IPv6
#ifndef CONFIG_NET_IPv6
/* Recalculate the IP checksum. */
BUF->ipchksum = 0;
BUF->ipchksum = ~(uip_ipchksum());
#endif /* CONFIG_NET_UIP_IPv6 */
#endif /* CONFIG_NET_IPv6 */
/* Transmit the second packet. */
/* uip_fw_output();*/
+262 -178
View File
File diff suppressed because it is too large Load Diff