当前位置:首页 > LwIP Application Developers Manual 中文翻译
/**
* Reads from the serial device. *
* @param fd serial device handle
* @param data pointer to data buffer for receiving
* @param len maximum length (in bytes) of data to receive * @return number of bytes actually received - may be 0 if aborted by sio_read_abort * */
u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len);
sio_read_abort函数将会导致sio_read操作马上退出。当要结束一个PPP会话时(终止、断开连接、明确关闭),tcpip_thread将调用sio_read_abord函数。该函数模型如下所示: /**
* Aborts a blocking sio_read() call. *
* @param fd serial device handle */
void sio_read_abort(sio_fd_t fd);
25 / 88
必须的回调函数
该回调函数的模型如下所示:
void (*linkStatusCB)(void *ctx, int errCode, void *arg) 该函数主要被如下事件所调用:
? 链接终止。errCode是一个非零值,arg为null
? sigup(Interface Up)。errCode为PPPERR_NONE,arg是一个指向ppp_addrs结构体的指针,该结构体包含了IP地址
? sifdown(Interface
Down)
。
errCode
为
PPPERR_CONNECT,arg为null errCode可以为如下一些数值:
#define PPPERR_NONE 0 /* No error. */
#define PPPERR_PARAM -1 /* Invalid parameter. */ #define PPPERR_OPEN -2 /* Unable to open PPP session. */
#define PPPERR_DEVICE -3 /* Invalid I/O device for PPP. */
#define PPPERR_ALLOC -4 /* Unable to allocate resources. */
#define PPPERR_USER -5 /* User interrupt. */ #define PPPERR_CONNECT -6 /* Connection lost. */ #define PPPERR_AUTHFAIL -7 /* Failed authentication
26 / 88
challenge. */
#define PPPERR_PROTOCOL -8 /* Failed to meet protocol. */
ctx指针是一个可选的用户自定义的指针,且该指针被定义为函数topppOverSerialOpen的参数,该指针指向用户定义的数据,。
没有任务的支持时
你需要在主线程里面调用函数pppos_input(int pd, u_char*
data, int len)来接收串行数据。
应用任务的代码
这个例子显示了TCP和PPP线程的初始化。假设你将会处
理你的socket在main()函数中上下文中。 #include \
#define PPP_SERIAL_PORT 0
static void linkStatusCB(void* ctx, int errCode, void* arg);
int main(void) { int connected = 0; int setup = 0;
27 / 88
int pd;
const char *username = \ const char *password = \
/* initialise lwIP. This creates a new thread, tcpip_thread, that
* communicates with the pppInputThread (see below) */ tcpip_init(tcpip_init_done, &setup); while (!setup) { sleep(1); }
/* initialise PPP. This needs to be done only once after boot up, to
* initialize global variables, etc. */ pppInit(); /*
set
the
method
of
authentication.
Use
PPPAUTHTYPE_PAP, or
* PPPAUTHTYPE_CHAP for more security . *
If
this
is
not
called,
the
default
is
PPPAUTHTYPE_NONE.
28 / 88
共分享92篇相关文档