2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
2009-06-15 20:58:22 +02:00
|
|
|
* net/net_internal.h
|
2007-09-01 20:06:15 +02:00
|
|
|
*
|
2009-06-15 20:58:22 +02:00
|
|
|
* Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
2007-09-01 20:06:15 +02:00
|
|
|
* 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.
|
2008-11-18 18:30:30 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-09-01 20:06:15 +02:00
|
|
|
* 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
|
|
|
|
|
2009-12-15 16:57:25 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
2007-09-09 13:58:50 +02:00
|
|
|
#include <time.h>
|
2009-12-15 16:57:25 +01:00
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#include <nuttx/net.h>
|
2007-11-22 15:42:52 +01:00
|
|
|
#include <net/uip/uip.h>
|
2007-09-01 20:06:15 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-09 19:20:56 +02:00
|
|
|
/* Definitions of 8-bit socket flags */
|
|
|
|
|
2009-07-19 15:50:08 +02:00
|
|
|
/* Bits 0-2: Socket state */
|
2007-09-09 19:20:56 +02:00
|
|
|
#define _SF_IDLE 0x00 /* There is no socket activity */
|
2007-09-23 22:45:30 +02:00
|
|
|
#define _SF_ACCEPT 0x01 /* Socket is waiting to accept a connection */
|
2007-09-09 19:20:56 +02:00
|
|
|
#define _SF_RECV 0x02 /* Waiting for recv action to complete */
|
|
|
|
#define _SF_SEND 0x03 /* Waiting for send action to complete */
|
|
|
|
#define _SF_MASK 0x03 /* Mask to isolate the above actions */
|
2009-07-19 15:50:08 +02:00
|
|
|
/* Bit 3: unused */
|
|
|
|
#define _SF_NONBLOCK 0x10 /* Bit 4: Don't block if no data (TCP/READ only) */
|
2007-09-23 22:45:30 +02:00
|
|
|
#define _SF_LISTENING 0x20 /* Bit 5: SOCK_STREAM is listening */
|
2007-09-09 19:20:56 +02:00
|
|
|
#define _SF_BOUND 0x40 /* Bit 6: SOCK_STREAM is bound to an address */
|
|
|
|
#define _SF_CONNECTED 0x80 /* Bit 7: SOCK_STREAM is connected */
|
|
|
|
|
|
|
|
/* Macro to manage the socket state and flags */
|
|
|
|
|
|
|
|
#define _SS_SETSTATE(s,f) (((s) & ~_SF_MASK) | (f))
|
|
|
|
#define _SS_GETSTATE(s) ((s) & _SF_MASK)
|
|
|
|
#define _SS_ISBUSY(s) (_SS_GETSTATE(s) != _SF_IDLE)
|
2009-07-19 15:50:08 +02:00
|
|
|
|
|
|
|
#define _SS_ISNONBLOCK(s) (((s) & _SF_NONBLOCK) != 0)
|
2007-09-23 22:45:30 +02:00
|
|
|
#define _SS_ISLISTENING(s) (((s) & _SF_LISTENING) != 0)
|
2007-09-09 19:20:56 +02:00
|
|
|
#define _SS_ISBOUND(s) (((s) & _SF_CONNECTED) != 0)
|
2007-09-23 22:45:30 +02:00
|
|
|
#define _SS_ISCONNECTED(s) (((s) & _SF_CONNECTED) != 0)
|
2007-09-09 19:20:56 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* This macro converts a socket option value into a bit setting */
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_BIT(o) (1 << (o))
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* These define bit positions for each socket option (see sys/socket.h) */
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_DEBUG _SO_BIT(SO_DEBUG)
|
|
|
|
#define _SO_ACCEPTCONN _SO_BIT(SO_ACCEPTCONN)
|
|
|
|
#define _SO_BROADCAST _SO_BIT(SO_BROADCAST)
|
|
|
|
#define _SO_REUSEADDR _SO_BIT(SO_REUSEADDR)
|
|
|
|
#define _SO_KEEPALIVE _SO_BIT(SO_KEEPALIVE)
|
|
|
|
#define _SO_LINGER _SO_BIT(SO_LINGER)
|
|
|
|
#define _SO_OOBINLINE _SO_BIT(SO_OOBINLINE)
|
|
|
|
#define _SO_SNDBUF _SO_BIT(SO_SNDBUF)
|
|
|
|
#define _SO_RCVBUF _SO_BIT(SO_RCVBUF)
|
|
|
|
#define _SO_ERROR _SO_BIT(SO_ERROR)
|
|
|
|
#define _SO_TYPE _SO_BIT(SO_TYPE)
|
|
|
|
#define _SO_DONTROUTE _SO_BIT(SO_DONTROUTE)
|
|
|
|
#define _SO_RCVLOWAT _SO_BIT(SO_RCVLOWAT)
|
|
|
|
#define _SO_RCVTIMEO _SO_BIT(SO_RCVTIMEO)
|
|
|
|
#define _SO_SNDLOWAT _SO_BIT(SO_SNDLOWAT)
|
|
|
|
#define _SO_SNDTIMEO _SO_BIT(SO_SNDTIMEO)
|
|
|
|
|
|
|
|
/* This is the larget option value */
|
|
|
|
|
|
|
|
#define _SO_MAXOPT (15)
|
|
|
|
|
|
|
|
/* Macros to set, test, clear options */
|
|
|
|
|
|
|
|
#define _SO_SETOPT(s,o) ((s) |= _SO_BIT(o))
|
|
|
|
#define _SO_CLROPT(s,o) ((s) &= ~_SO_BIT(o))
|
|
|
|
#define _SO_GETOPT(s,o) (((s) & _SO_BIT(o)) != 0)
|
|
|
|
|
|
|
|
/* These are macros that can be used to determine if socket option code is
|
|
|
|
* valid (in range) and supported by API.
|
2007-09-07 02:10:10 +02:00
|
|
|
*/
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
#define _SO_GETONLYSET (_SO_ACCEPTCONN|_SO_ERROR|_SO_TYPE)
|
|
|
|
#define _SO_GETONLY(o) ((_SO_BIT(o) & _SO_GETONLYSET) != 0)
|
|
|
|
#define _SO_GETVALID(o) (((unsigned int)(o)) <= _SO_MAXOPT)
|
|
|
|
#define _SO_SETVALID(o) ((((unsigned int)(o)) <= _SO_MAXOPT) && !_SO_GETONLY(o))
|
2007-09-07 02:10:10 +02:00
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Variables
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-09-16 19:46:25 +02:00
|
|
|
/* List of registered ethernet device drivers */
|
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
extern struct uip_driver_s *g_netdevices;
|
|
|
|
extern sem_t g_netdev_sem;
|
|
|
|
#endif
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
/****************************************************************************
|
2008-08-02 19:22:22 +02:00
|
|
|
* Public Function Prototypes
|
2007-09-01 20:06:15 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
|
|
|
extern "C" {
|
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_sockets.c *************************************************************/
|
2007-09-01 20:06:15 +02:00
|
|
|
|
2009-07-19 02:14:46 +02:00
|
|
|
EXTERN int sockfd_allocate(int minsd);
|
2009-09-16 22:29:00 +02:00
|
|
|
EXTERN void sock_release(FAR struct socket *psock);
|
2007-09-01 22:56:19 +02:00
|
|
|
EXTERN void sockfd_release(int sockfd);
|
|
|
|
EXTERN FAR struct socket *sockfd_socket(int sockfd);
|
2007-09-01 20:06:15 +02:00
|
|
|
|
2009-09-16 22:29:00 +02:00
|
|
|
/* net_close.c ***************************************************************/
|
|
|
|
|
|
|
|
EXTERN int net_closesocket(FAR struct socket *psock);
|
|
|
|
|
2007-09-08 21:50:59 +02:00
|
|
|
/* sockopt support ***********************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK)
|
2009-12-15 16:57:25 +01:00
|
|
|
EXTERN int net_timeo(uint32_t start_time, socktimeo_t timeo);
|
2007-09-09 00:41:00 +02:00
|
|
|
EXTERN socktimeo_t net_timeval2dsec(struct timeval *tv);
|
2009-12-15 16:57:25 +01:00
|
|
|
EXTERN void net_dsec2timeval(uint16_t dsec, struct timeval *tv);
|
2007-09-08 21:50:59 +02:00
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_register.c ************************************************************/
|
2007-09-16 19:46:25 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
EXTERN void netdev_semtake(void);
|
|
|
|
# define netdev_semgive() sem_post(&g_netdev_sem)
|
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_findbyname.c **********************************************************/
|
2007-09-16 19:46:25 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2007-11-22 15:42:52 +01:00
|
|
|
EXTERN FAR struct uip_driver_s *netdev_findbyname(const char *ifname);
|
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_findbyaddr.c **********************************************************/
|
2007-11-22 15:42:52 +01:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2008-09-03 18:14:00 +02:00
|
|
|
EXTERN FAR struct uip_driver_s *netdev_findbyaddr(const uip_ipaddr_t *raddr);
|
2007-11-22 15:42:52 +01:00
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_txnotify.c ************************************************************/
|
2007-11-22 15:42:52 +01:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
2008-09-03 18:14:00 +02:00
|
|
|
EXTERN void netdev_txnotify(const uip_ipaddr_t *raddr);
|
2007-09-17 00:12:04 +02:00
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_count.c ***************************************************************/
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
#if CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
EXTERN int netdev_count(void);
|
2007-09-16 19:46:25 +02:00
|
|
|
#endif
|
|
|
|
|
2009-06-15 20:58:22 +02:00
|
|
|
/* net_arptimer.c ************************************************************/
|
2007-11-02 21:20:34 +01:00
|
|
|
|
|
|
|
EXTERN void arptimer_init(void);
|
|
|
|
|
2007-09-01 20:06:15 +02:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET */
|
|
|
|
#endif /* __NET_INTERNAL_H */
|