mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-11 20:55:39 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
356
Living_SDK/device/sal/include/internal/sal_arch_internal.h
Normal file
356
Living_SDK/device/sal/include/internal/sal_arch_internal.h
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_ARCH_INTERNAL_H_
|
||||
#define _SAL_ARCH_INTERNAL_H_
|
||||
|
||||
#include <aos/aos.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup sys_time
|
||||
* Returns the current time in milliseconds,
|
||||
* may be the same as sys_jiffies or at least based on it.
|
||||
*/
|
||||
uint32_t sys_now(void);
|
||||
|
||||
//#define EVENT_SIMPLE
|
||||
#define SAL_ARCH_TIMEOUT 0xffffffffUL
|
||||
|
||||
/** sys_mbox_tryfetch() returns SAL_MBOX_EMPTY if appropriate.
|
||||
* For now we use the same magic value, but we allow this to change in future.
|
||||
*/
|
||||
#define SAL_MBOX_EMPTY SAL_ARCH_TIMEOUT
|
||||
|
||||
#define SAL_SEM_NULL NULL
|
||||
|
||||
#define SAL_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define SAL_DEFAULT_INPUTMBOX_SIZE 8
|
||||
#define SAL_DEFAULT_OUTPUTMBOX_SIZE 8
|
||||
|
||||
typedef aos_sem_t sal_sem_t;
|
||||
|
||||
#define sal_sem_valid(sem) aos_sem_is_valid(sem)
|
||||
#define sal_sem_set_invalid(sem) do { if(sem != NULL) { (sem)->hdl = NULL; }}while(0)
|
||||
|
||||
typedef uint32_t sal_prot_t;
|
||||
|
||||
typedef aos_mutex_t sal_mutex_t;
|
||||
#define sal_mutex_valid(mutex) aos_mutex_is_valid(mutex)
|
||||
#define sal_mutex_set_invalid(mutex) do { if(mutex != NULL) { (mutex)->hdl = NULL; }}while(0)
|
||||
|
||||
typedef aos_queue_t sal_mbox_t;
|
||||
#define sal_mbox_valid(mbox) aos_queue_is_valid(mbox)
|
||||
#define sal_mbox_set_invalid(mbox) do { if(mbox != NULL) { (mbox)->hdl = NULL; }}while(0)
|
||||
|
||||
typedef void *sal_thread_t;
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Create a new mutex.
|
||||
* Note that mutexes are expected to not be taken recursively by the lwIP code,
|
||||
* so both implementation types (recursive or non-recursive) should work.
|
||||
* @param mutex pointer to the mutex to create
|
||||
* @return ERR_OK if successful, another err_t otherwise
|
||||
*/
|
||||
err_t sal_mutex_new(sal_mutex_t *mutex);
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Lock a mutex
|
||||
* @param mutex the mutex to lock
|
||||
*/
|
||||
void sal_mutex_lock(sal_mutex_t *mutex);
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Unlock a mutex
|
||||
* @param mutex the mutex to unlock
|
||||
*/
|
||||
void sal_mutex_unlock(sal_mutex_t *mutex);
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Delete a semaphore
|
||||
* @param mutex the mutex to delete
|
||||
*/
|
||||
void sal_mutex_free(sal_mutex_t *mutex);
|
||||
#ifndef sal_mutex_valid
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sal_mutex_valid(sal_mutex_t *mutex);
|
||||
#endif
|
||||
#ifndef sal_mutex_set_invalid
|
||||
/**
|
||||
* @ingroup sal_mutex
|
||||
* Set a mutex invalid so that sal_mutex_valid returns 0
|
||||
*/
|
||||
void sal_mutex_set_invalid(sal_mutex_t *mutex);
|
||||
#endif
|
||||
/* Semaphore functions: */
|
||||
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Create a new semaphore
|
||||
* @param sem pointer to the semaphore to create
|
||||
* @param count initial count of the semaphore
|
||||
* @return ERR_OK if successful, another err_t otherwise
|
||||
*/
|
||||
err_t sal_sem_new(sal_sem_t *sem, uint8_t count);
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Signals a semaphore
|
||||
* @param sem the semaphore to signal
|
||||
*/
|
||||
void sal_sem_signal(sal_sem_t *sem);
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Wait for a semaphore for the specified timeout
|
||||
* @param sem the semaphore to wait for
|
||||
* @param timeout timeout in milliseconds to wait (0 = wait forever)
|
||||
* @return time (in milliseconds) waited for the semaphore
|
||||
* or SAL_ARCH_TIMEOUT on timeout
|
||||
*/
|
||||
uint32_t sal_arch_sem_wait(sal_sem_t *sem, uint32_t timeout);
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Delete a semaphore
|
||||
* @param sem semaphore to delete
|
||||
*/
|
||||
void sal_sem_free(sal_sem_t *sem);
|
||||
/** Wait for a semaphore - forever/no timeout */
|
||||
#define sal_sem_wait(sem) sal_arch_sem_wait(sem, 0)
|
||||
#ifndef sal_sem_valid
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Check if a semaphore is valid/allocated: return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sal_sem_valid(sal_sem_t *sem);
|
||||
#endif
|
||||
#ifndef sal_sem_set_invalid
|
||||
/**
|
||||
* @ingroup sal_sem
|
||||
* Set a semaphore invalid so that sal_sem_valid returns 0
|
||||
*/
|
||||
void sal_sem_set_invalid(sal_sem_t *sem);
|
||||
#endif
|
||||
#ifndef sal_sem_valid_val
|
||||
/**
|
||||
* Same as sal_sem_valid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_sem_valid_val(sem) sal_sem_valid(&(sem))
|
||||
#endif
|
||||
#ifndef sal_sem_set_invalid_val
|
||||
/**
|
||||
* Same as sal_sem_set_invalid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_sem_set_invalid_val(sem) sal_sem_set_invalid(&(sem))
|
||||
#endif
|
||||
|
||||
/* sal_mutex_arch_init() must be called before anything else. */
|
||||
void sal_mutex_arch_init(void);
|
||||
|
||||
void sal_mutex_arch_free(void);
|
||||
|
||||
/* Mailbox functions. */
|
||||
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Create a new mbox of specified size
|
||||
* @param mbox pointer to the mbox to create
|
||||
* @param size (minimum) number of messages in this mbox
|
||||
* @return ERR_OK if successful, another err_t otherwise
|
||||
*/
|
||||
err_t sal_mbox_new(sal_mbox_t *mbox, int size);
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Post a message to an mbox - may not fail
|
||||
* -> blocks if full, only used from tasks not from ISR
|
||||
* @param mbox mbox to posts the message
|
||||
* @param msg message to post (ATTENTION: can be NULL)
|
||||
*/
|
||||
void sal_mbox_post(sal_mbox_t *mbox, void *msg);
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Try to post a message to an mbox - may fail if full or ISR
|
||||
* @param mbox mbox to posts the message
|
||||
* @param msg message to post (ATTENTION: can be NULL)
|
||||
*/
|
||||
err_t sal_mbox_trypost(sal_mbox_t *mbox, void *msg);
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Wait for a new message to arrive in the mbox
|
||||
* @param mbox mbox to get a message from
|
||||
* @param msg pointer where the message is stored
|
||||
* @param timeout maximum time (in milliseconds) to wait for a message (0 = wait forever)
|
||||
* @return time (in milliseconds) waited for a message, may be 0 if not waited
|
||||
or SYS_ARCH_TIMEOUT on timeout
|
||||
* The returned time has to be accurate to prevent timer jitter!
|
||||
*/
|
||||
u32_t sal_arch_mbox_fetch(sal_mbox_t *mbox, void **msg, u32_t timeout);
|
||||
/* Allow port to override with a macro, e.g. special timeout for sys_arch_mbox_fetch() */
|
||||
#ifndef sal_arch_mbox_tryfetch
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Wait for a new message to arrive in the mbox
|
||||
* @param mbox mbox to get a message from
|
||||
* @param msg pointer where the message is stored
|
||||
* @return 0 (milliseconds) if a message has been received
|
||||
* or SAL_MBOX_EMPTY if the mailbox is empty
|
||||
*/
|
||||
u32_t sal_arch_mbox_tryfetch(sal_mbox_t *mbox, void **msg);
|
||||
#endif
|
||||
/**
|
||||
* For now, we map straight to sys_arch implementation.
|
||||
*/
|
||||
#define sal_mbox_tryfetch(mbox, msg) sal_arch_mbox_tryfetch(mbox, msg)
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Delete an mbox
|
||||
* @param mbox mbox to delete
|
||||
*/
|
||||
void sal_mbox_free(sal_mbox_t *mbox);
|
||||
|
||||
#define sal_mbox_fetch(mbox, msg) sal_arch_mbox_fetch(mbox, msg, 0)
|
||||
#ifndef sal_mbox_valid
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid
|
||||
*/
|
||||
int sal_mbox_valid(sal_mbox_t *mbox);
|
||||
#endif
|
||||
#ifndef sal_mbox_set_invalid
|
||||
/**
|
||||
* @ingroup sys_mbox
|
||||
* Set an mbox invalid so that sys_mbox_valid returns 0
|
||||
*/
|
||||
void sal_mbox_set_invalid(sal_mbox_t *mbox);
|
||||
#endif
|
||||
#ifndef sal_mbox_valid_val
|
||||
/**
|
||||
* Same as sys_mbox_valid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_mbox_valid_val(mbox) sal_mbox_valid(&(mbox))
|
||||
#endif
|
||||
#ifndef sal_mbox_set_invalid_val
|
||||
/**
|
||||
* Same as sys_mbox_set_invalid() but taking a value, not a pointer
|
||||
*/
|
||||
#define sal_mbox_set_invalid_val(mbox) sal_mbox_set_invalid(&(mbox))
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup sal_time
|
||||
* Returns the current time in milliseconds,
|
||||
* may be the same as sal_jiffies or at least based on it.
|
||||
*/
|
||||
uint32_t sal_now(void);
|
||||
|
||||
/* Critical Region Protection */
|
||||
/* These functions must be implemented in the sal_arch.c file.
|
||||
In some implementations they can provide a more light-weight protection
|
||||
mechanism than using semaphores. Otherwise semaphores can be used for
|
||||
implementation */
|
||||
#ifndef SAL_ARCH_PROTECT
|
||||
/** SAL_LIGHTWEIGHT_PROT
|
||||
* define SAL_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
|
||||
* for certain critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#if SAL_LIGHTWEIGHT_PROT
|
||||
|
||||
/**
|
||||
* @ingroup sal_prot
|
||||
* SAL_ARCH_DECL_PROTECT
|
||||
* declare a protection variable. This macro will default to defining a variable of
|
||||
* type sal_prot_t. If a particular port needs a different implementation, then
|
||||
* this macro may be defined in sal_arch.h.
|
||||
*/
|
||||
#define SAL_ARCH_DECL_PROTECT(lev) sal_prot_t lev
|
||||
/**
|
||||
* @ingroup sal_prot
|
||||
* SAL_ARCH_PROTECT
|
||||
* Perform a "fast" protect. This could be implemented by
|
||||
* disabling interrupts for an embedded system or by using a semaphore or
|
||||
* mutex. The implementation should allow calling SAL_ARCH_PROTECT when
|
||||
* already protected. The old protection level is returned in the variable
|
||||
* "lev". This macro will default to calling the sal_arch_protect() function
|
||||
* which should be implemented in sal_arch.c. If a particular port needs a
|
||||
* different implementation, then this macro may be defined in sal_arch.h
|
||||
*/
|
||||
#define SAL_ARCH_PROTECT(lev) lev = sal_arch_protect()
|
||||
/**
|
||||
* @ingroup sal_prot
|
||||
* SAL_ARCH_UNPROTECT
|
||||
* Perform a "fast" set of the protection level to "lev". This could be
|
||||
* implemented by setting the interrupt level to "lev" within the MACRO or by
|
||||
* using a semaphore or mutex. This macro will default to calling the
|
||||
* sal_arch_unprotect() function which should be implemented in
|
||||
* sal_arch.c. If a particular port needs a different implementation, then
|
||||
* this macro may be defined in sal_arch.h
|
||||
*/
|
||||
#define SAL_ARCH_UNPROTECT(lev) sal_arch_unprotect(lev)
|
||||
sal_prot_t sal_arch_protect(void);
|
||||
void sal_arch_unprotect(sal_prot_t pval);
|
||||
|
||||
#else
|
||||
|
||||
#define SAL_ARCH_DECL_PROTECT(lev)
|
||||
#define SAL_ARCH_PROTECT(lev)
|
||||
#define SAL_ARCH_UNPROTECT(lev)
|
||||
|
||||
#endif /* SAL_LIGHTWEIGHT_PROT */
|
||||
|
||||
#endif /* SAL_ARCH_PROTECT */
|
||||
|
||||
/*
|
||||
* Macros to set/get and increase/decrease variables in a thread-safe way.
|
||||
* Use these for accessing variable that are used from more than one thread.
|
||||
*/
|
||||
|
||||
#ifndef SAL_ARCH_INC
|
||||
#define SAL_ARCH_INC(var, val) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
var += val; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_INC */
|
||||
|
||||
#ifndef SAL_ARCH_DEC
|
||||
#define SAL_ARCH_DEC(var, val) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
var -= val; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_DEC */
|
||||
|
||||
#ifndef SAL_ARCH_GET
|
||||
#define SAL_ARCH_GET(var, ret) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
ret = var; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_GET */
|
||||
|
||||
#ifndef SAL_ARCH_SET
|
||||
#define SAL_ARCH_SET(var, val) do { \
|
||||
SAL_ARCH_DECL_PROTECT(old_level); \
|
||||
SAL_ARCH_PROTECT(old_level); \
|
||||
var = val; \
|
||||
SAL_ARCH_UNPROTECT(old_level); \
|
||||
} while(0)
|
||||
#endif /* SAL_ARCH_SET */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_SAL_ARCH_H_*/
|
||||
200
Living_SDK/device/sal/include/internal/sal_pcb.h
Normal file
200
Living_SDK/device/sal/include/internal/sal_pcb.h
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_PCB_H_
|
||||
#define _SAL_PCB_H_
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if SAL_NETIF_HWADDRHINT
|
||||
#define IP_PCB_ADDRHINT ;u8_t addr_hint
|
||||
#else
|
||||
#define IP_PCB_ADDRHINT
|
||||
#endif
|
||||
|
||||
/** Main packet buffer struct */
|
||||
struct pbuf {
|
||||
/** next pbuf in singly linked pbuf chain */
|
||||
struct pbuf *next;
|
||||
|
||||
/** pointer to the actual data in the buffer */
|
||||
void *payload;
|
||||
|
||||
/**
|
||||
* total length of this buffer and all next buffers in chain
|
||||
* belonging to the same packet.
|
||||
*
|
||||
* For non-queue packet chains this is the invariant:
|
||||
* p->tot_len == p->len + (p->next? p->next->tot_len: 0)
|
||||
*/
|
||||
u16_t tot_len;
|
||||
|
||||
/** length of this buffer */
|
||||
u16_t len;
|
||||
|
||||
/** pbuf_type as u8_t instead of enum to save space */
|
||||
u8_t /*pbuf_type*/ type;
|
||||
|
||||
/** misc flags */
|
||||
u8_t flags;
|
||||
|
||||
#if SAL_XR_EXT_MBUF_SUPPORT
|
||||
/** new flags for mbuf */
|
||||
u8_t mb_flags;
|
||||
|
||||
/** decrease its size to u8_t */
|
||||
u8_t ref;
|
||||
#else /* SAL_XR_EXT_MBUF_SUPPORT */
|
||||
/**
|
||||
* the reference count always equals the number of pointers
|
||||
* that refer to this pbuf. This can be pointers from an application,
|
||||
* the stack itself, or pbuf->next pointers from a chain.
|
||||
*/
|
||||
u16_t ref;
|
||||
#endif
|
||||
};
|
||||
/** This is the common part of all PCB types. It needs to be at the
|
||||
beginning of a PCB type definition. It is located here so that
|
||||
changes to this common part are made in one location instead of
|
||||
having to change all PCB structs. */
|
||||
#define IP_PCB \
|
||||
/* ip addresses in network byte order */ \
|
||||
ip_addr_t local_ip; \
|
||||
ip_addr_t remote_ip; \
|
||||
/* Socket options */ \
|
||||
u8_t so_options; \
|
||||
/* Type Of Service */ \
|
||||
u8_t tos; \
|
||||
/* Time To Live */ \
|
||||
u8_t ttl \
|
||||
/* link layer address resolution hint */ \
|
||||
IP_PCB_ADDRHINT
|
||||
|
||||
struct ip_pcb {
|
||||
/* Common members of all PCB types */
|
||||
IP_PCB;
|
||||
};
|
||||
|
||||
struct tcp_pcb;
|
||||
typedef void (*tcp_recv_fn)(void *arg, struct tcp_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port);
|
||||
/**
|
||||
* members common to struct tcp_pcb and struct tcp_listen_pcb
|
||||
*/
|
||||
#define TCP_PCB_COMMON(type) \
|
||||
type *next; /* for the linked list */ \
|
||||
void *callback_arg; \
|
||||
u8_t prio; \
|
||||
/* ports are in host byte order */ \
|
||||
u16_t local_port
|
||||
|
||||
/** the TCP protocol control block */
|
||||
struct tcp_pcb {
|
||||
/** common PCB members */
|
||||
IP_PCB;
|
||||
/** protocol specific PCB members */
|
||||
TCP_PCB_COMMON(struct tcp_pcb);
|
||||
|
||||
/* ports are in host byte order */
|
||||
u16_t remote_port;
|
||||
/** receive callback function */
|
||||
tcp_recv_fn recv;
|
||||
/* user-supplied argument for the recv callback */
|
||||
void *recv_arg;
|
||||
};
|
||||
|
||||
struct udp_pcb;
|
||||
|
||||
/** Function prototype for udp pcb receive callback functions
|
||||
* addr and port are in same byte order as in the pcb
|
||||
* The callback is responsible for freeing the pbuf
|
||||
* if it's not used any more.
|
||||
*
|
||||
* ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf
|
||||
* can make 'addr' invalid, too.
|
||||
*
|
||||
* @param arg user supplied argument (udp_pcb.recv_arg)
|
||||
* @param pcb the udp_pcb which received data
|
||||
* @param p the packet buffer that was received
|
||||
* @param addr the remote IP address from which the packet was received
|
||||
* @param port the remote port from which the packet was received
|
||||
*/
|
||||
typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr, u16_t port);
|
||||
|
||||
/** the UDP protocol control block */
|
||||
struct udp_pcb {
|
||||
/** Common members of all PCB types */
|
||||
IP_PCB;
|
||||
|
||||
/* Protocol specific PCB members */
|
||||
|
||||
struct udp_pcb *next;
|
||||
|
||||
u8_t flags;
|
||||
/** ports are in host byte order */
|
||||
u16_t local_port, remote_port;
|
||||
|
||||
#if SAL_MULTICAST_TX_OPTIONS
|
||||
/** outgoing network interface for multicast packets */
|
||||
ip_addr_t multicast_ip;
|
||||
/** TTL for outgoing multicast packets */
|
||||
u8_t mcast_ttl;
|
||||
#endif /* SAL_MULTICAST_TX_OPTIONS */
|
||||
|
||||
#if SAL_UDPLITE
|
||||
/** used for UDP_LITE only */
|
||||
u16_t chksum_len_rx, chksum_len_tx;
|
||||
#endif /* SAL_UDPLITE */
|
||||
|
||||
/** receive callback function */
|
||||
udp_recv_fn recv;
|
||||
/** user-supplied argument for the recv callback */
|
||||
void *recv_arg;
|
||||
};
|
||||
|
||||
struct raw_pcb;
|
||||
|
||||
/** Function prototype for raw pcb receive callback functions.
|
||||
* @param arg user supplied argument (raw_pcb.recv_arg)
|
||||
* @param pcb the raw_pcb which received data
|
||||
* @param p the packet buffer that was received
|
||||
* @param addr the remote IP address from which the packet was received
|
||||
* @return 1 if the packet was 'eaten' (aka. deleted),
|
||||
* 0 if the packet lives on
|
||||
* If returning 1, the callback is responsible for freeing the pbuf
|
||||
* if it's not used any more.
|
||||
*/
|
||||
typedef u8_t (*raw_recv_fn)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
||||
const ip_addr_t *addr);
|
||||
|
||||
/** the RAW protocol control block */
|
||||
struct raw_pcb {
|
||||
/* Common members of all PCB types */
|
||||
IP_PCB;
|
||||
|
||||
struct raw_pcb *next;
|
||||
|
||||
u8_t protocol;
|
||||
|
||||
/** receive callback function */
|
||||
raw_recv_fn recv;
|
||||
/* user-supplied argument for the recv callback */
|
||||
void *recv_arg;
|
||||
#if SAL_IPV6
|
||||
/* fields for handling checksum computations as per RFC3542. */
|
||||
u16_t chksum_offset;
|
||||
u8_t chksum_reqd;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AOS_EVENTFD_H__ */
|
||||
|
||||
270
Living_SDK/device/sal/include/internal/sal_sockets_internal.h
Normal file
270
Living_SDK/device/sal/include/internal/sal_sockets_internal.h
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_SOCKETS_INTERNAL_H_
|
||||
#define _SAL_SOCKETS_INTERNAL_H_
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
#include <aos/aos.h>
|
||||
#include "vfs_conf.h"
|
||||
#include "sal_arch.h"
|
||||
#include "sal_def.h"
|
||||
#include "sal_ipaddr.h"
|
||||
#include "sal_err.h"
|
||||
#include "sal_pcb.h"
|
||||
#include "sal_arch_internal.h"
|
||||
#include "sal.h"
|
||||
#include "sal_sockets.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_NETCONN 5//(MAX_SOCKETS_TCP + MAX_LISTENING_SOCKETS_TCP + MAX_SOCKETS_UDP)
|
||||
|
||||
#define SAL_TAG "sal"
|
||||
|
||||
#ifdef SAL_USE_DEBUG
|
||||
#define SAL_DEBUG(format, ...) LOGD(SAL_TAG, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define SAL_DEBUG(format, ...)
|
||||
#endif
|
||||
|
||||
#define SAL_ERROR(format, ...) LOGE(SAL_TAG, format, ##__VA_ARGS__)
|
||||
#define SAL_ASSERT(msg, assertion) do { if (!(assertion)) { \
|
||||
LOGE(SAL_TAG, msg);} \
|
||||
} while (0)
|
||||
|
||||
/** IPv4 only: set the IP address given as an u32_t */
|
||||
#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
|
||||
/** IPv4 only: get the IP address as an u32_t */
|
||||
#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
|
||||
|
||||
/* Helpers to process several netconn_types by the same code */
|
||||
#define NETCONNTYPE_GROUP(t) ((t)&0xF0)
|
||||
#define NETCONNTYPE_DATAGRAM(t) ((t)&0xE0)
|
||||
|
||||
#if SAL_NETCONN_SEM_PER_THREAD
|
||||
#define SELECT_SEM_T sal_sem_t*
|
||||
#define SELECT_SEM_PTR(sem) (sem)
|
||||
#else /* SAL_NETCONN_SEM_PER_THREAD */
|
||||
#define SELECT_SEM_T sal_sem_t
|
||||
#define SELECT_SEM_PTR(sem) (&(sem))
|
||||
#endif /* SAL_NETCONN_SEM_PER_THREAD */
|
||||
|
||||
/* Flags for struct netconn.flags (u8_t) */
|
||||
/** Should this netconn avoid blocking? */
|
||||
#define NETCONN_FLAG_NON_BLOCKING 0x02
|
||||
/** Was the last connect action a non-blocking one? */
|
||||
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
|
||||
|
||||
/** Set the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_set_nonblocking(conn, val) do { if(val) { \
|
||||
(conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
|
||||
} else { \
|
||||
(conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
|
||||
/** Get the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
|
||||
|
||||
|
||||
// #if defined(AOS_CONFIG_VFS_DEV_NODES)
|
||||
// #define SAL_SOCKET_OFFSET AOS_CONFIG_VFS_DEV_NODES
|
||||
// #endif
|
||||
|
||||
#define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
|
||||
|
||||
typedef struct sal_netbuf{
|
||||
void *payload;
|
||||
u16_t len;
|
||||
ip_addr_t addr;
|
||||
u16_t port;
|
||||
}sal_netbuf_t;
|
||||
|
||||
typedef struct sal_outputbuf{
|
||||
void *payload;
|
||||
u16_t len;
|
||||
u16_t remote_port;
|
||||
char remote_ip[16];
|
||||
}sal_outputbuf_t;
|
||||
|
||||
/** Description for a task waiting in select */
|
||||
struct sal_select_cb {
|
||||
/** Pointer to the next waiting task */
|
||||
struct sal_select_cb *next;
|
||||
/** Pointer to the previous waiting task */
|
||||
struct sal_select_cb *prev;
|
||||
/** readset passed to select */
|
||||
fd_set *readset;
|
||||
/** writeset passed to select */
|
||||
fd_set *writeset;
|
||||
/** unimplemented: exceptset passed to select */
|
||||
fd_set *exceptset;
|
||||
/** don't signal the same semaphore twice: set to 1 when signalled */
|
||||
int sem_signalled;
|
||||
/** semaphore to wake up a task waiting for select */
|
||||
SELECT_SEM_T sem;
|
||||
};
|
||||
|
||||
/** Current state of the netconn. Non-TCP netconns are always
|
||||
* in state NETCONN_NONE! */
|
||||
enum netconn_state {
|
||||
NETCONN_NONE,
|
||||
NETCONN_WRITE,
|
||||
NETCONN_LISTEN,
|
||||
NETCONN_CONNECT,
|
||||
NETCONN_CLOSE
|
||||
};
|
||||
|
||||
/* Flags for struct netconn.flags (u8_t) */
|
||||
/** Should this netconn avoid blocking? */
|
||||
#define NETCONN_FLAG_NON_BLOCKING 0x02
|
||||
/** Was the last connect action a non-blocking one? */
|
||||
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
|
||||
/** If a nonblocking write has been rejected before, poll_tcp needs to
|
||||
check if the netconn is writable again */
|
||||
#define NETCONN_FLAG_CHECK_WRITESPACE 0x10
|
||||
/** If this flag is set then only IPv6 communication is allowed on the
|
||||
netconn. As per RFC#3493 this features defaults to OFF allowing
|
||||
dual-stack usage by default. */
|
||||
#define NETCONN_FLAG_IPV6_V6ONLY 0x20
|
||||
|
||||
/** @ingroup netconn_common
|
||||
* Protocol family and type of the netconn
|
||||
*/
|
||||
enum netconn_type {
|
||||
NETCONN_INVALID = 0,
|
||||
/** TCP IPv4 */
|
||||
NETCONN_TCP = 0x10,
|
||||
#if SAL_IPV6
|
||||
/** TCP IPv6 */
|
||||
NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6 /* 0x18 */,
|
||||
#endif /* SAL_IPV6 */
|
||||
/** UDP IPv4 */
|
||||
NETCONN_UDP = 0x20,
|
||||
/** UDP IPv4 lite */
|
||||
NETCONN_UDPLITE = 0x21,
|
||||
/** UDP IPv4 no checksum */
|
||||
NETCONN_UDPNOCHKSUM = 0x22,
|
||||
|
||||
#if SAL_IPV6
|
||||
/** UDP IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6 /* 0x28 */,
|
||||
/** UDP IPv6 lite (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6 /* 0x29 */,
|
||||
/** UDP IPv6 no checksum (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6 /* 0x2a */,
|
||||
#endif /* SAL_IPV6 */
|
||||
|
||||
/** Raw connection IPv4 */
|
||||
NETCONN_RAW = 0x40
|
||||
#if SAL_IPV6
|
||||
/** Raw connection IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */
|
||||
, NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */
|
||||
#endif /* SAL_IPV6 */
|
||||
};
|
||||
|
||||
struct sal_netconn;
|
||||
/** A callback prototype to inform about events for a netconn */
|
||||
typedef void (* netconn_callback)(struct sal_netconn *conn, enum netconn_evt, u16_t len);
|
||||
|
||||
/** A netconn descriptor */
|
||||
typedef struct sal_netconn {
|
||||
int socket;
|
||||
/** type of the netconn (TCP, UDP or RAW) */
|
||||
enum netconn_type type;
|
||||
/** current state of the netconn */
|
||||
enum netconn_state state;
|
||||
|
||||
/** the SAL internal protocol control block */
|
||||
union {
|
||||
struct ip_pcb *ip;
|
||||
struct tcp_pcb *tcp;
|
||||
struct udp_pcb *udp;
|
||||
struct raw_pcb *raw;
|
||||
} pcb;
|
||||
/** the last error this netconn had */
|
||||
err_t last_err;
|
||||
|
||||
/** mbox where received packets are stored until they are fetched
|
||||
by the neconn application thread. */
|
||||
sal_mbox_t recvmbox;
|
||||
|
||||
sal_mbox_t sendmbox;
|
||||
|
||||
/** flags holding more netconn-internal state, see NETCONN_FLAG_* defines */
|
||||
u8_t flags;
|
||||
/** timeout to wait for sending data (which means enqueueing data for sending
|
||||
in internal buffers) in milliseconds */
|
||||
s32_t send_timeout;
|
||||
/** timeout in milliseconds to wait for new data to be received
|
||||
(or connections to arrive for listening netconns) */
|
||||
int recv_timeout;
|
||||
#if SAL_RCVBUF
|
||||
/** maximum amount of bytes queued in recvmbox
|
||||
not used for TCP: adjust TCP_WND instead! */
|
||||
int recv_bufsize;
|
||||
/** number of bytes currently in recvmbox to be received,
|
||||
tested against recv_bufsize to limit bytes on recvmbox
|
||||
for UDP and RAW, used for FIONREAD */
|
||||
int recv_avail;
|
||||
#endif /* SAL_RCVBUF */
|
||||
/** A callback function that is informed about events for this netconn */
|
||||
netconn_callback callback;
|
||||
} sal_netconn_t;
|
||||
|
||||
/** Set the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_set_nonblocking(conn, val) do { if(val) { \
|
||||
(conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
|
||||
} else { \
|
||||
(conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
|
||||
/** Get the blocking status of netconn calls (@todo: write/send is missing) */
|
||||
#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
|
||||
|
||||
#define SAL_SO_SNDRCVTIMEO_GET_MS(optval) ((((const struct timeval *)(optval))->tv_sec * 1000U) + (((const struct timeval *)(optval))->tv_usec / 1000U))
|
||||
|
||||
#define SAL_SOCKET_MAX_PAYLOAD_SIZE 1512
|
||||
#define SAL_SOCKET_IP4_ANY_ADDR "0.0.0.0"
|
||||
#define SAL_SOCKET_IP4_ADDR_LEN 16
|
||||
|
||||
void sal_deal_event(int s, enum netconn_evt evt);
|
||||
|
||||
#define API_EVENT_SIMPLE(s,e) sal_deal_event(s,e)
|
||||
|
||||
#define EAI_NONAME 200
|
||||
#define EAI_SERVICE 201
|
||||
#define EAI_FAIL 202
|
||||
#define EAI_MEMORY 203
|
||||
#define EAI_FAMILY 204
|
||||
|
||||
#define HOST_NOT_FOUND 210
|
||||
#define NO_DATA 211
|
||||
#define NO_RECOVERY 212
|
||||
#define TRY_AGAIN 213
|
||||
|
||||
/* input flags for struct addrinfo */
|
||||
#define AI_PASSIVE 0x01
|
||||
#define AI_CANONNAME 0x02
|
||||
#define AI_NUMERICHOST 0x04
|
||||
#define AI_NUMERICSERV 0x08
|
||||
#define AI_V4MAPPED 0x10
|
||||
#define AI_ALL 0x20
|
||||
#define AI_ADDRCONFIG 0x40
|
||||
|
||||
struct sockaddr_storage {
|
||||
u8_t s2_len;
|
||||
sa_family_t ss_family;
|
||||
char s2_data1[2];
|
||||
u32_t s2_data2[3];
|
||||
#if LWIP_IPV6
|
||||
u32_t s2_data3[3];
|
||||
#endif /* LWIP_IPV6 */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __AOS_EVENTFD_H__ */
|
||||
225
Living_SDK/device/sal/include/sal.h
Normal file
225
Living_SDK/device/sal/include/sal.h
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_H_
|
||||
#define _SAL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SAL_PACKET_SEND_MODE_ASYNC 1
|
||||
|
||||
typedef enum {
|
||||
/* WiFi */
|
||||
TCP_SERVER,
|
||||
TCP_CLIENT,
|
||||
SSL_CLIENT,
|
||||
UDP_BROADCAST,
|
||||
UDP_UNICAST,
|
||||
/*WiFi end */
|
||||
/* Add others hereafter */
|
||||
} CONN_TYPE;
|
||||
|
||||
/* Fill necessary fileds according to the socket type. */
|
||||
typedef struct {
|
||||
int fd; /* fd that are used in socket level */
|
||||
CONN_TYPE type;
|
||||
char *addr; /* remote ip or domain */
|
||||
int32_t r_port; /* remote port (set to -1 if not used) */
|
||||
int32_t l_port; /* local port (set to -1 if not used) */
|
||||
uint32_t tcp_keep_alive; /* tcp keep alive value (set to 0 if not used) */
|
||||
} sal_conn_t;
|
||||
|
||||
/* Socket data state indicator. */
|
||||
typedef enum netconn_evt {
|
||||
NETCONN_EVT_RCVPLUS,
|
||||
NETCONN_EVT_RCVMINUS,
|
||||
NETCONN_EVT_SENDPLUS,
|
||||
NETCONN_EVT_SENDMINUS,
|
||||
NETCONN_EVT_ERROR
|
||||
} netconn_evt_t;
|
||||
|
||||
typedef int (*netconn_data_input_cb_t)(int fd, void *data, size_t len, char remote_ip[16], uint16_t remote_port);
|
||||
|
||||
typedef struct sal_op_s {
|
||||
char *version; /* Reserved for furture use. */
|
||||
|
||||
/**
|
||||
* Module low level init so that it's ready to setup socket connection.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*init)(void);
|
||||
|
||||
/**
|
||||
* Start a socket connection via module.
|
||||
*
|
||||
* @param[in] c - connect parameters which are used to setup
|
||||
* the socket connection.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*start)(sal_conn_t *c);
|
||||
|
||||
/**
|
||||
* Send data via module.
|
||||
* This function does not return until all data sent.
|
||||
*
|
||||
* @param[in] fd - the file descripter to operate on.
|
||||
* @param[in] data - pointer to data to send.
|
||||
* @param[in] len - length of the data.
|
||||
* @param[in] remote_ip - remote ip address (optional).
|
||||
* @param[in] remote_port - remote port number (optional).
|
||||
* @param[in] timeout - packet send timeout (ms)
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*send)(int fd, uint8_t *data, uint32_t len,
|
||||
char remote_ip[16], int32_t remote_port, int32_t timeout);
|
||||
|
||||
int (*recv)(int fd, uint8_t *data, uint32_t len,
|
||||
char remote_ip[16], int32_t remote_port);
|
||||
|
||||
/**
|
||||
* Get IP information of the corresponding domain.
|
||||
* Currently only one IP string is returned (even when the domain
|
||||
* coresponses to mutliple IPs). Note: only IPv4 is supported.
|
||||
*
|
||||
* @param[in] domain - the domain string.
|
||||
* @param[out] ip - the place to hold the dot-formatted ip string.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*domain_to_ip)(char *domain, char ip[16]);
|
||||
|
||||
/**
|
||||
* Close the socket connection.
|
||||
*
|
||||
* @param[in] fd - the file descripter to operate on.
|
||||
* @param[in] remote_port - remote port number (optional).
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*close)(int fd, int32_t remote_port);
|
||||
|
||||
/**
|
||||
* Destroy SAL or exit low level state if necessary.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*deinit)(void);
|
||||
|
||||
/**
|
||||
* Register network connection data input function
|
||||
* Input data from module.
|
||||
* This callback should be called when the data is received from the module
|
||||
* It should tell the sal where the data comes from.
|
||||
* @param[in] fd - the file descripter to operate on.
|
||||
* @param[in] data - the received data.
|
||||
* @param[in] len - expected length of the data when IN,
|
||||
* and real read len when OUT.
|
||||
* @param[in] addr - remote ip address. Caller manages the
|
||||
memory (optional).
|
||||
* @param[in] port - remote port number (optional).
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int (*register_netconn_data_input_cb)(netconn_data_input_cb_t cb);
|
||||
} sal_op_t;
|
||||
|
||||
|
||||
/**
|
||||
* Register a module instance to the SAL
|
||||
*
|
||||
* @param[in] module the module instance
|
||||
**/
|
||||
int sal_module_register(sal_op_t *module);
|
||||
|
||||
/**
|
||||
* Module low level init so that it's ready to setup socket connection.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_init(void);
|
||||
|
||||
/**
|
||||
* Start a socket connection via module.
|
||||
*
|
||||
* @param[in] conn - connect parameters which are used to setup
|
||||
* the socket connection.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_start(sal_conn_t *conn);
|
||||
|
||||
/**
|
||||
* Send data via module.
|
||||
* This function does not return until all data sent.
|
||||
*
|
||||
* @param[in] fd - the file descripter to operate on.
|
||||
* @param[in] data - pointer to data to send.
|
||||
* @param[in] len - length of the data.
|
||||
* @param[in] remote_ip - remote port number (optional).
|
||||
* @param[in] remote_port - remote port number (optional).
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_send(int fd, uint8_t *data, uint32_t len, char remote_ip[16],
|
||||
int32_t remote_port, int32_t timeout);
|
||||
|
||||
/**
|
||||
* Get IP information of the corresponding domain.
|
||||
* Currently only one IP string is returned (even when the domain
|
||||
* coresponses to mutliple IPs). Note: only IPv4 is supported.
|
||||
*
|
||||
* @param[in] domain - the domain string.
|
||||
* @param[out] ip - the place to hold the dot-formatted ip string.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_domain_to_ip(char *domain, char ip[16]);
|
||||
|
||||
/**
|
||||
* Close the socket connection.
|
||||
*
|
||||
* @param[in] fd - the file descripter to operate on.
|
||||
* @param[in] remote_port - remote port number (optional).
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_close(int fd, int32_t remote_port);
|
||||
|
||||
/**
|
||||
* Destroy SAL or exit low level state if necessary.
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_deinit(void);
|
||||
|
||||
/**
|
||||
* Register network connection data input function
|
||||
* Input data from module.
|
||||
* This callback should be called when the data is received from the module
|
||||
* It should tell the sal where the data comes from.
|
||||
* @param[in] fd - the file descripter to operate on.
|
||||
* @param[in] data - the received data.
|
||||
* @param[in] len - expected length of the data when IN,
|
||||
* and real read len when OUT.
|
||||
* @param[in] addr - remote ip address. Caller manages the
|
||||
memory (optional).
|
||||
* @param[in] port - remote port number (optional).
|
||||
*
|
||||
* @return 0 - success, -1 - failure
|
||||
*/
|
||||
int sal_module_register_netconn_data_input_cb(netconn_data_input_cb_t cb);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
35
Living_SDK/device/sal/include/sal_arch.h
Normal file
35
Living_SDK/device/sal/include/sal_arch.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef SAL_ARCH_H
|
||||
#define SAL_ARCH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef LITTLE_ENDIAN
|
||||
#define LITTLE_ENDIAN 1234
|
||||
#endif
|
||||
|
||||
#ifndef BIG_ENDIAN
|
||||
#define BIG_ENDIAN 4321
|
||||
#endif
|
||||
|
||||
/* Define generic types used in sal */
|
||||
#if !SAL_NO_STDINT_H
|
||||
#include <stdint.h>
|
||||
typedef uint8_t u8_t;
|
||||
typedef int8_t s8_t;
|
||||
typedef uint16_t u16_t;
|
||||
typedef int16_t s16_t;
|
||||
typedef uint32_t u32_t;
|
||||
typedef int32_t s32_t;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
40
Living_SDK/device/sal/include/sal_def.h
Normal file
40
Living_SDK/device/sal/include/sal_def.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef SAL_DEF_H
|
||||
#define SAL_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define sal_htons(x) (x)
|
||||
#define sal_ntohs(x) (x)
|
||||
#define sal_htonl(x) (x)
|
||||
#define sal_ntohl(x) (x)
|
||||
#else
|
||||
#define sal_htons(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
|
||||
#define sal_ntohs(x) sal_htons(x)
|
||||
#define sal_htonl(x) ((((x) & 0xff) << 24) | \
|
||||
(((x) & 0xff00) << 8) | \
|
||||
(((x) & 0xff0000UL) >> 8) | \
|
||||
(((x) & 0xff000000UL) >> 24))
|
||||
#define sal_ntohl(x) sal_htonl(x)
|
||||
#endif
|
||||
|
||||
#define htons(x) sal_htons(x)
|
||||
|
||||
#define ntohs(x) sal_ntohs(x)
|
||||
|
||||
#define htonl(x) sal_htonl(x)
|
||||
|
||||
#define ntohl(x) sal_ntohl(x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
185
Living_SDK/device/sal/include/sal_err.h
Normal file
185
Living_SDK/device/sal/include/sal_err.h
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _ERR_H_
|
||||
#define _ERR_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int8_t err_t;
|
||||
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Arg list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define EDEADLK 35 /* Resource deadlock would occur */
|
||||
#define ENAMETOOLONG 36 /* File name too long */
|
||||
#define ENOLCK 37 /* No record locks available */
|
||||
#define ENOSYS 38 /* Function not implemented */
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
#define ELOOP 40 /* Too many symbolic links encountered */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
#define ENOMSG 42 /* No message of desired type */
|
||||
#define EIDRM 43 /* Identifier removed */
|
||||
#define ECHRNG 44 /* Channel number out of range */
|
||||
#define EL2NSYNC 45 /* Level 2 not synchronized */
|
||||
#define EL3HLT 46 /* Level 3 halted */
|
||||
#define EL3RST 47 /* Level 3 reset */
|
||||
#define ELNRNG 48 /* Link number out of range */
|
||||
#define EUNATCH 49 /* Protocol driver not attached */
|
||||
#define ENOCSI 50 /* No CSI structure available */
|
||||
#define EL2HLT 51 /* Level 2 halted */
|
||||
#define EBADE 52 /* Invalid exchange */
|
||||
#define EBADR 53 /* Invalid request descriptor */
|
||||
#define EXFULL 54 /* Exchange full */
|
||||
#define ENOANO 55 /* No anode */
|
||||
#define EBADRQC 56 /* Invalid request code */
|
||||
#define EBADSLT 57 /* Invalid slot */
|
||||
|
||||
#define EDEADLOCK EDEADLK
|
||||
|
||||
#define EBFONT 59 /* Bad font file format */
|
||||
#define ENOSTR 60 /* Device not a stream */
|
||||
#define ENODATA 61 /* No data available */
|
||||
#define ETIME 62 /* Timer expired */
|
||||
#define ENOSR 63 /* Out of streams resources */
|
||||
#define ENONET 64 /* Machine is not on the network */
|
||||
#define ENOPKG 65 /* Package not installed */
|
||||
#define EREMOTE 66 /* Object is remote */
|
||||
#define ENOLINK 67 /* Link has been severed */
|
||||
#define EADV 68 /* Advertise error */
|
||||
#define ESRMNT 69 /* Srmount error */
|
||||
#define ECOMM 70 /* Communication error on send */
|
||||
#define EPROTO 71 /* Protocol error */
|
||||
#define EMULTIHOP 72 /* Multihop attempted */
|
||||
#define EDOTDOT 73 /* RFS specific error */
|
||||
#define EBADMSG 74 /* Not a data message */
|
||||
#define EOVERFLOW 75 /* Value too large for defined data type */
|
||||
#define ENOTUNIQ 76 /* Name not unique on network */
|
||||
#define EBADFD 77 /* File descriptor in bad state */
|
||||
#define EREMCHG 78 /* Remote address changed */
|
||||
#define ELIBACC 79 /* Can not access a needed shared library */
|
||||
#define ELIBBAD 80 /* Accessing a corrupted shared library */
|
||||
#define ELIBSCN 81 /* .lib section in a.out corrupted */
|
||||
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
|
||||
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
|
||||
#define EILSEQ 84 /* Illegal byte sequence */
|
||||
#define ERESTART 85 /* Interrupted system call should be restarted */
|
||||
#define ESTRPIPE 86 /* Streams pipe error */
|
||||
#define EUSERS 87 /* Too many users */
|
||||
#define ENOTSOCK 88 /* Socket operation on non-socket */
|
||||
#define EDESTADDRREQ 89 /* Destination address required */
|
||||
#define EMSGSIZE 90 /* Message too long */
|
||||
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
|
||||
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||
#define EPROTONOSUPPORT 93 /* Protocol not supported */
|
||||
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
|
||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define EPFNOSUPPORT 96 /* Protocol family not supported */
|
||||
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define EADDRINUSE 98 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||
#define ENETDOWN 100 /* Network is down */
|
||||
#define ENETUNREACH 101 /* Network is unreachable */
|
||||
#define ENETRESET 102 /* Network dropped connection because of reset */
|
||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||
#define ECONNRESET 104 /* Connection reset by peer */
|
||||
#define ENOBUFS 105 /* No buffer space available */
|
||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
|
||||
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
|
||||
#define ETIMEDOUT 110 /* Connection timed out */
|
||||
#define ECONNREFUSED 111 /* Connection refused */
|
||||
#define EHOSTDOWN 112 /* Host is down */
|
||||
#define EHOSTUNREACH 113 /* No route to host */
|
||||
#define EALREADY 114 /* Operation already in progress */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ESTALE 116 /* Stale NFS file handle */
|
||||
#define EUCLEAN 117 /* Structure needs cleaning */
|
||||
#define ENOTNAM 118 /* Not a XENIX named type file */
|
||||
#define ENAVAIL 119 /* No XENIX semaphores available */
|
||||
#define EISNAM 120 /* Is a named type file */
|
||||
#define EREMOTEIO 121 /* Remote I/O error */
|
||||
#define EDQUOT 122 /* Quota exceeded */
|
||||
|
||||
#define ENOMEDIUM 123 /* No medium found */
|
||||
#define EMEDIUMTYPE 124 /* Wrong medium type */
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
/** Definitions for error constants. */
|
||||
typedef enum {
|
||||
/** No error, everything OK. */
|
||||
ERR_OK = 0,
|
||||
/** Out of memory error. */
|
||||
ERR_MEM = -1,
|
||||
/** Buffer error. */
|
||||
ERR_BUF = -2,
|
||||
/** Timeout. */
|
||||
ERR_TIMEOUT = -3,
|
||||
/** Routing problem. */
|
||||
ERR_RTE = -4,
|
||||
/** Operation in progress */
|
||||
ERR_INPROGRESS = -5,
|
||||
/** Illegal value. */
|
||||
ERR_VAL = -6,
|
||||
/** Operation would block. */
|
||||
ERR_WOULDBLOCK = -7,
|
||||
/** Address in use. */
|
||||
ERR_USE = -8,
|
||||
/** Already connecting. */
|
||||
ERR_ALREADY = -9,
|
||||
/** Conn already established.*/
|
||||
ERR_ISCONN = -10,
|
||||
/** Not connected. */
|
||||
ERR_CONN = -11,
|
||||
/** Low-level netif error */
|
||||
ERR_IF = -12,
|
||||
/** Connection aborted. */
|
||||
ERR_ABRT = -13,
|
||||
/** Connection reset. */
|
||||
ERR_RST = -14,
|
||||
/** Connection closed. */
|
||||
ERR_CLSD = -15,
|
||||
/** Illegal argument. */
|
||||
ERR_ARG = -16
|
||||
} err_enum_t;
|
||||
|
||||
const char *sal_strerr(err_t err);
|
||||
int err_to_errno(err_t err);
|
||||
|
||||
#endif
|
||||
98
Living_SDK/device/sal/include/sal_ipaddr.h
Normal file
98
Living_SDK/device/sal/include/sal_ipaddr.h
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_IPADDR_H_
|
||||
#define _SAL_IPADDR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* If your port already typedef's in_addr_t, define IN_ADDR_T_DEFINED
|
||||
to prevent this code from redefining it. */
|
||||
#if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
|
||||
typedef u32_t in_addr_t;
|
||||
#endif
|
||||
|
||||
struct in_addr {
|
||||
in_addr_t s_addr;
|
||||
};
|
||||
|
||||
struct in6_addr {
|
||||
union {
|
||||
u32_t u32_addr[4];
|
||||
u8_t u8_addr[16];
|
||||
} un;
|
||||
#define s6_addr un.u8_addr
|
||||
};
|
||||
|
||||
enum sal_ip_addr_type {
|
||||
/** IPv4 */
|
||||
IPADDR_TYPE_V4 = 0U,
|
||||
/** IPv6 */
|
||||
IPADDR_TYPE_V6 = 6U,
|
||||
/** IPv4+IPv6 ("dual-stack") */
|
||||
IPADDR_TYPE_ANY = 46U
|
||||
};
|
||||
|
||||
typedef struct ip4_addr {
|
||||
u32_t addr;
|
||||
} ip4_addr_t;
|
||||
|
||||
typedef struct ip6_addr {
|
||||
u32_t addr[4];
|
||||
} ip6_addr_t;
|
||||
|
||||
typedef struct _ip_addr {
|
||||
union {
|
||||
ip6_addr_t ip6;
|
||||
ip4_addr_t ip4;
|
||||
} u_addr;
|
||||
/** @ref sal_ip_addr_type */
|
||||
u8_t type;
|
||||
} ip_addr_t;
|
||||
|
||||
/** 255.255.255.255 */
|
||||
#define IPADDR_NONE ((u32_t)0xffffffffUL)
|
||||
/** 127.0.0.1 */
|
||||
#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
|
||||
/** 0.0.0.0 */
|
||||
#define IPADDR_ANY ((u32_t)0x00000000UL)
|
||||
/** 255.255.255.255 */
|
||||
#define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
|
||||
|
||||
/** 255.255.255.255 */
|
||||
#define IPADDR_NONE ((u32_t)0xffffffffUL)
|
||||
/** 127.0.0.1 */
|
||||
#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
|
||||
/** 0.0.0.0 */
|
||||
#define IPADDR_ANY ((u32_t)0x00000000UL)
|
||||
/** 255.255.255.255 */
|
||||
#define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
|
||||
|
||||
/** 255.255.255.255 */
|
||||
#define INADDR_NONE IPADDR_NONE
|
||||
/** 127.0.0.1 */
|
||||
#define INADDR_LOOPBACK IPADDR_LOOPBACK
|
||||
/** 0.0.0.0 */
|
||||
#define INADDR_ANY IPADDR_ANY
|
||||
/** 255.255.255.255 */
|
||||
#define INADDR_BROADCAST IPADDR_BROADCAST
|
||||
|
||||
#define IPADDR_BROADCAST_STRING "255.255.255.255"
|
||||
|
||||
in_addr_t ipaddr_addr(const char *cp);
|
||||
int ip4addr_aton(const char *cp, ip4_addr_t *addr);
|
||||
char *ip4addr_ntoa(const ip4_addr_t *addr);
|
||||
|
||||
#define inet_addr(cp) ipaddr_addr(cp)
|
||||
#define inet_aton(cp,addr) ip4addr_aton(cp,(ip4_addr_t*)addr)
|
||||
#define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
325
Living_SDK/device/sal/include/sal_sockets.h
Normal file
325
Living_SDK/device/sal/include/sal_sockets.h
Normal file
|
|
@ -0,0 +1,325 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _SAL_SOCKET_H_
|
||||
#define _SAL_SOCKET_H_
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <sys/time.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AF_UNSPEC 0
|
||||
#define AF_INET 2
|
||||
#define AF_INET6 10
|
||||
#define PF_INET AF_INET
|
||||
#define PF_INET6 AF_INET6
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_ICMP 1
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
/* Socket protocol types (TCP/UDP/RAW) */
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
#define SOCK_RAW 3
|
||||
|
||||
#define IP_MULTICAST_TTL 5
|
||||
#define IP_MULTICAST_IF 6
|
||||
#define IP_MULTICAST_LOOP 7
|
||||
|
||||
|
||||
/* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
|
||||
to prevent this code from redefining it. */
|
||||
#if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
|
||||
typedef u8_t sa_family_t;
|
||||
#endif
|
||||
/* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
|
||||
to prevent this code from redefining it. */
|
||||
#if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
|
||||
typedef u16_t in_port_t;
|
||||
#endif
|
||||
|
||||
#define DNS_MAX_NAME_LENGTH 256
|
||||
|
||||
struct sockaddr {
|
||||
u8_t sa_len;
|
||||
sa_family_t sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
/* members are in network byte order */
|
||||
struct sockaddr_in {
|
||||
u8_t sin_len;
|
||||
sa_family_t sin_family;
|
||||
in_port_t sin_port;
|
||||
struct in_addr sin_addr;
|
||||
#define SIN_ZERO_LEN 8
|
||||
char sin_zero[SIN_ZERO_LEN];
|
||||
};
|
||||
|
||||
struct sockaddr_in6 {
|
||||
u8_t sin6_len; /* length of this structure */
|
||||
sa_family_t sin6_family; /* AF_INET6 */
|
||||
in_port_t sin6_port; /* Transport layer port # */
|
||||
u32_t sin6_flowinfo; /* IPv6 flow information */
|
||||
struct in6_addr sin6_addr; /* IPv6 address */
|
||||
u32_t sin6_scope_id; /* Set of interfaces for scope */
|
||||
};
|
||||
|
||||
/* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED
|
||||
to prevent this code from redefining it. */
|
||||
#if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
|
||||
typedef u32_t socklen_t;
|
||||
#endif
|
||||
|
||||
struct hostent {
|
||||
char *h_name; /* Official name of the host. */
|
||||
char **h_aliases; /* A pointer to an array of pointers to alternative
|
||||
host names, terminated by a null pointer. */
|
||||
int h_addrtype; /* Address type. */
|
||||
int h_length; /* The length, in bytes, of the address. */
|
||||
char **h_addr_list; /* A pointer to an array of pointers to network
|
||||
addresses (in network byte order) for the host,
|
||||
terminated by a null pointer. */
|
||||
#define h_addr h_addr_list[0] /* for backward compatibility */
|
||||
};
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags; /* Input flags. */
|
||||
int ai_family; /* Address family of socket. */
|
||||
int ai_socktype; /* Socket type. */
|
||||
int ai_protocol; /* Protocol of socket. */
|
||||
socklen_t ai_addrlen; /* Length of socket address. */
|
||||
struct sockaddr *ai_addr; /* Socket address of socket. */
|
||||
char *ai_canonname; /* Canonical name of service location. */
|
||||
struct addrinfo *ai_next; /* Pointer to next in list. */
|
||||
};
|
||||
|
||||
#define SOL_SOCKET 0xfff /* options for socket level */
|
||||
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_ICMP 1
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
#define IPPROTO_IPV6 41
|
||||
#define IPPROTO_ICMPV6 58
|
||||
|
||||
#define IPPROTO_UDPLITE 136
|
||||
#define IPPROTO_RAW 255
|
||||
|
||||
/* Flags we can use with send and recv. */
|
||||
#define MSG_PEEK 0x01 /* Peeks at an incoming message */
|
||||
#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
|
||||
#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
|
||||
#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
|
||||
#define MSG_MORE 0x10 /* Sender will send more */
|
||||
|
||||
#define MEMP_NUM_NETCONN 5//(MAX_SOCKETS_TCP + MAX_LISTENING_SOCKETS_TCP + MAX_SOCKETS_UDP)
|
||||
|
||||
#ifndef SAL_SOCKET_OFFSET
|
||||
#define SAL_SOCKET_OFFSET 0
|
||||
#endif
|
||||
|
||||
/* FD_SET used for event_select */
|
||||
#ifndef FD_SET
|
||||
#undef FD_SETSIZE
|
||||
/* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
|
||||
#define FD_SETSIZE MEMP_NUM_NETCONN
|
||||
|
||||
#define FDSETSAFESET(n, code) do { \
|
||||
if (((n) - SAL_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - SAL_SOCKET_OFFSET) >= 0)) { \
|
||||
code; }} while(0)
|
||||
#define FDSETSAFEGET(n, code) (((n) - SAL_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - SAL_SOCKET_OFFSET) >= 0) ?\
|
||||
(code) : 0)
|
||||
#define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-SAL_SOCKET_OFFSET)/8] |= (1 << (((n)-SAL_SOCKET_OFFSET) & 7)))
|
||||
#define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-SAL_SOCKET_OFFSET)/8] &= ~(1 << (((n)-SAL_SOCKET_OFFSET) & 7)))
|
||||
#define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-SAL_SOCKET_OFFSET)/8] & (1 << (((n)-SAL_SOCKET_OFFSET) & 7)))
|
||||
#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
|
||||
|
||||
typedef struct fd_set {
|
||||
unsigned char fd_bits [(FD_SETSIZE * 2 + 7) / 8];
|
||||
} fd_set;
|
||||
|
||||
#elif SAL_SOCKET_OFFSET
|
||||
#error SAL_SOCKET_OFFSET does not work with external FD_SET!
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#endif /* FD_SET */
|
||||
|
||||
/*
|
||||
* Options and types related to multicast membership
|
||||
*/
|
||||
#define IP_ADD_MEMBERSHIP 3
|
||||
#define IP_DROP_MEMBERSHIP 4
|
||||
|
||||
#define IP_MULTICAST_TTL 5
|
||||
#define IP_MULTICAST_IF 6
|
||||
#define IP_MULTICAST_LOOP 7
|
||||
|
||||
|
||||
typedef struct ip_mreq {
|
||||
struct in_addr imr_multiaddr; /* IP multicast address of group */
|
||||
struct in_addr imr_interface; /* local IP address of interface */
|
||||
} ip_mreq;
|
||||
|
||||
/*
|
||||
* Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
|
||||
*/
|
||||
#define SO_REUSEADDR 0x0004 /* Allow local address reuse */
|
||||
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
|
||||
#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
|
||||
|
||||
/*
|
||||
* Additional options, not kept in so_options.
|
||||
*/
|
||||
#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
|
||||
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
|
||||
#define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
|
||||
#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
|
||||
#define SO_LINGER 0x0080 /* linger on close if data present */
|
||||
#define SO_DONTLINGER ((int)(~SO_LINGER))
|
||||
#define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
|
||||
#define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
|
||||
#define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
|
||||
#define SO_RCVBUF 0x1002 /* receive buffer size */
|
||||
#define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
|
||||
#define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
|
||||
#define SO_SNDTIMEO 0x1005 /* send timeout */
|
||||
#define SO_RCVTIMEO 0x1006 /* receive timeout */
|
||||
#define SO_ERROR 0x1007 /* get error status and clear */
|
||||
#define SO_TYPE 0x1008 /* get socket type */
|
||||
#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
|
||||
#define SO_NO_CHECK 0x100a /* don't create UDP checksum */
|
||||
|
||||
const void *ur_adapter_get_default_ipaddr(void);
|
||||
const void *ur_adapter_get_mcast_ipaddr(void);
|
||||
|
||||
int sal_select(int maxfdp1, fd_set *readset, fd_set *writeset,
|
||||
fd_set *exceptset, struct timeval *timeout);
|
||||
|
||||
int sal_socket(int domain, int type, int protocol);
|
||||
|
||||
int sal_write(int s, const void *data, size_t size);
|
||||
|
||||
int sal_connect(int s, const struct sockaddr *name, socklen_t namelen);
|
||||
|
||||
int sal_bind(int s, const struct sockaddr *name, socklen_t namelen);
|
||||
|
||||
int sal_eventfd(unsigned int initval, int flags);
|
||||
|
||||
int sal_setsockopt(int s, int level, int optname,
|
||||
const void *optval, socklen_t optlen);
|
||||
|
||||
int sal_getsockopt(int s, int level, int optname,
|
||||
void *optval, socklen_t *optlen);
|
||||
|
||||
struct hostent *sal_gethostbyname(const char *name);
|
||||
|
||||
int sal_close(int s);
|
||||
|
||||
int sal_init(void);
|
||||
|
||||
int sal_sendto(int s, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen);
|
||||
|
||||
int sal_send(int s, const void *data, size_t size, int flags);
|
||||
|
||||
int sal_shutdown(int s, int how);
|
||||
|
||||
int sal_recvfrom(int s, void *mem, size_t len, int flags,
|
||||
struct sockaddr *from, socklen_t *fromlen);
|
||||
|
||||
int sal_recv(int s, void *mem, size_t len, int flags);
|
||||
|
||||
int sal_read(int s, void *mem, size_t len);
|
||||
|
||||
void sal_freeaddrinfo(struct addrinfo *ai);
|
||||
|
||||
int sal_getaddrinfo(const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res);
|
||||
|
||||
|
||||
|
||||
void sal_freeaddrinfo(struct addrinfo *ai);
|
||||
|
||||
int sal_shutdown(int s, int how);
|
||||
|
||||
int sal_getaddrinfo(const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res);
|
||||
|
||||
int sal_fcntl(int s, int cmd, int val);
|
||||
#define select(maxfdp1,readset,writeset,exceptset,timeout) \
|
||||
sal_select(maxfdp1,readset,writeset,exceptset,timeout)
|
||||
|
||||
#define write(s,data,size) \
|
||||
sal_write(s,data,size)
|
||||
|
||||
#define socket(domain,type,protocol) \
|
||||
sal_socket(domain,type,protocol)
|
||||
|
||||
#define connect(s,name,namelen) \
|
||||
sal_connect(s,name,namelen)
|
||||
|
||||
#define bind(s,name,namelen) \
|
||||
sal_bind(s,name,namelen)
|
||||
|
||||
#define shutdown(s,how) \
|
||||
sal_shutdown(s,how)
|
||||
|
||||
#define eventfd(initval,flags) \
|
||||
sal_eventfd(initval,flags)
|
||||
|
||||
#define setsockopt(s,level,optname,optval,optlen) \
|
||||
sal_setsockopt(s,level,optname,optval,optlen)
|
||||
|
||||
#define getsockopt(s,level,optname,optval,optlen) \
|
||||
sal_getsockopt(s,level,optname,optval,optlen)
|
||||
|
||||
#define gethostbyname(name) \
|
||||
sal_gethostbyname(name)
|
||||
|
||||
#define close(s) \
|
||||
sal_close(s)
|
||||
|
||||
#define sendto(s,dataptr,size,flags,to,tolen) \
|
||||
sal_sendto(s,dataptr,size,flags,to,tolen)
|
||||
|
||||
#define recvfrom(s,mem,len,flags,from,fromlen) \
|
||||
sal_recvfrom(s,mem,len,flags,from,fromlen)
|
||||
|
||||
#define send(s,data,size,flags) \
|
||||
sal_send(s,data,size,flags)
|
||||
|
||||
#define recv(s,data,size,flags) \
|
||||
sal_recv(s,data,size,flags)
|
||||
|
||||
#define read(s,data,size) \
|
||||
sal_read(s,data,size)
|
||||
|
||||
#define freeaddrinfo(addrinfo) sal_freeaddrinfo(addrinfo)
|
||||
|
||||
#define getaddrinfo(nodname, servname, hints, res) \
|
||||
sal_getaddrinfo(nodname, servname, hints, res)
|
||||
|
||||
#define fcntl(s,cmd,val) sal_fcntl(s,cmd,val)
|
||||
|
||||
|
||||
|
||||
#define inet_ntop(af,src,dst,size) \
|
||||
(((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL)
|
||||
#define inet_pton(af,src,dst) \
|
||||
(((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue