Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

api.h File Reference

#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include "lwip/ip.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/err.h"

Include dependency graph for api.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  netbuf
struct  netconn

Defines

#define NETCONN_NOCOPY   0x00
#define NETCONN_COPY   0x01

Enumerations

enum  netconn_type { NETCONN_TCP, NETCONN_UDP, NETCONN_UDPLITE, NETCONN_UDPNOCHKSUM }
enum  netconn_state {
  NETCONN_NONE, NETCONN_WRITE, NETCONN_ACCEPT, NETCONN_RECV,
  NETCONN_CONNECT, NETCONN_CLOSE
}
enum  netconn_evt { NETCONN_EVT_RCVPLUS, NETCONN_EVT_RCVMINUS, NETCONN_EVT_SENDPLUS, NETCONN_EVT_SENDMINUS }

Functions

netbufnetbuf_new (void)
void netbuf_delete (struct netbuf *buf)
void * netbuf_alloc (struct netbuf *buf, u16_t size)
void netbuf_free (struct netbuf *buf)
void netbuf_ref (struct netbuf *buf, void *dataptr, u16_t size)
void netbuf_chain (struct netbuf *head, struct netbuf *tail)
u16_t netbuf_len (struct netbuf *buf)
err_t netbuf_data (struct netbuf *buf, void **dataptr, u16_t *len)
s8_t netbuf_next (struct netbuf *buf)
void netbuf_first (struct netbuf *buf)
void netbuf_copy (struct netbuf *buf, void *dataptr, u16_t len)
void netbuf_copy_partial (struct netbuf *buf, void *dataptr, u16_t len, u16_t offset)
ip_addrnetbuf_fromaddr (struct netbuf *buf)
u16_t netbuf_fromport (struct netbuf *buf)
netconnnetconn_new (enum netconn_type type)
netconnnetconn_new_with_callback (enum netconn_type t, void(*callback)(struct netconn *, enum netconn_evt, u16_t len))
err_t netconn_delete (struct netconn *conn)
enum netconn_type netconn_type (struct netconn *conn)
err_t netconn_peer (struct netconn *conn, struct ip_addr *addr, u16_t *port)
err_t netconn_addr (struct netconn *conn, struct ip_addr **addr, u16_t *port)
err_t netconn_bind (struct netconn *conn, struct ip_addr *addr, u16_t port)
err_t netconn_connect (struct netconn *conn, struct ip_addr *addr, u16_t port)
err_t netconn_disconnect (struct netconn *conn)
err_t netconn_listen (struct netconn *conn)
netconnnetconn_accept (struct netconn *conn)
netbufnetconn_recv (struct netconn *conn)
err_t netconn_send (struct netconn *conn, struct netbuf *buf)
err_t netconn_write (struct netconn *conn, void *dataptr, u16_t size, u8_t copy)
err_t netconn_close (struct netconn *conn)
err_t netconn_err (struct netconn *conn)


Define Documentation

#define NETCONN_COPY   0x01
 

Definition at line 54 of file api.h.

Referenced by lwip_send(), and tcp_client().

#define NETCONN_NOCOPY   0x00
 

Definition at line 53 of file api.h.


Enumeration Type Documentation

enum netconn_evt
 

Enumeration values:
NETCONN_EVT_RCVPLUS 
NETCONN_EVT_RCVMINUS 
NETCONN_EVT_SENDPLUS 
NETCONN_EVT_SENDMINUS 

Definition at line 72 of file api.h.

enum netconn_state
 

Enumeration values:
NETCONN_NONE 
NETCONN_WRITE 
NETCONN_ACCEPT 
NETCONN_RECV 
NETCONN_CONNECT 
NETCONN_CLOSE 

Definition at line 63 of file api.h.

00063                    {
00064   NETCONN_NONE,
00065   NETCONN_WRITE,
00066   NETCONN_ACCEPT,
00067   NETCONN_RECV,
00068   NETCONN_CONNECT,
00069   NETCONN_CLOSE
00070 };

enum netconn_type
 

Enumeration values:
NETCONN_TCP 
NETCONN_UDP 
NETCONN_UDPLITE 
NETCONN_UDPNOCHKSUM 

Definition at line 56 of file api.h.

Referenced by lwip_recvfrom(), and lwip_send().

00056                   {
00057   NETCONN_TCP,
00058   NETCONN_UDP,
00059   NETCONN_UDPLITE,
00060   NETCONN_UDPNOCHKSUM
00061 };


Function Documentation

void* netbuf_alloc struct netbuf buf,
u16_t  size
 

Definition at line 73 of file api_lib.c.

References NULL, netbuf::p, pbuf::payload, pbuf_alloc(), pbuf_free(), PBUF_RAM, PBUF_TRANSPORT, netbuf::ptr, and u16_t.

00074 {
00075   /* Deallocate any previously allocated memory. */
00076   if(buf->p != NULL) {
00077     pbuf_free(buf->p);
00078   }
00079   buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
00080   if(buf->p == NULL) {
00081      return NULL;
00082   }
00083   buf->ptr = buf->p;
00084   return buf->p->payload;
00085 }

Here is the call graph for this function:

void netbuf_chain struct netbuf head,
struct netbuf tail
 

Definition at line 109 of file api_lib.c.

References memp_freep(), MEMP_NETBUF, netbuf::p, pbuf_chain(), and netbuf::ptr.

00110 {
00111   pbuf_chain(head->p, tail->p);
00112   head->ptr = head->p;
00113   memp_freep(MEMP_NETBUF, tail);
00114 }

Here is the call graph for this function:

void netbuf_copy struct netbuf buf,
void *  dataptr,
u16_t  len
 

Definition at line 182 of file api_lib.c.

References len, netbuf_copy_partial(), and u16_t.

Referenced by udpecho_thread().

00183 {
00184   netbuf_copy_partial(buf, dataptr, len, 0);
00185 }

Here is the call graph for this function:

void netbuf_copy_partial struct netbuf buf,
void *  dataptr,
u16_t  len,
u16_t  offset
 

Definition at line 153 of file api_lib.c.

References len, NULL, netbuf::p, and u16_t.

Referenced by lwip_recvfrom(), and netbuf_copy().

00154 {
00155   struct pbuf *p;
00156   u16_t i, left;
00157 
00158   left = 0;
00159 
00160   if(buf == NULL) {
00161     return;
00162   }
00163   
00164   /* This implementation is bad. It should use bcopy
00165      instead. */
00166   for(p = buf->p; left < len && p != NULL; p = p->next) {
00167     if(offset != 0 && offset >= p->len) {
00168       offset -= p->len;
00169     } else {    
00170       for(i = offset; i < p->len; ++i) {
00171         ((char *)dataptr)[left] = ((char *)p->payload)[i];
00172         if(++left >= len) {
00173           return;
00174         }
00175       }
00176       offset = 0;
00177     }
00178   }
00179 }

err_t netbuf_data struct netbuf buf,
void **  dataptr,
u16_t len
 

Definition at line 123 of file api_lib.c.

References ERR_BUF, ERR_OK, pbuf::len, len, NULL, pbuf::payload, netbuf::ptr, and u16_t.

Referenced by serve_echo(), and tcpecho_thread().

00124 {
00125   if(buf->ptr == NULL) {
00126     return ERR_BUF;
00127   }
00128   *dataptr = buf->ptr->payload;
00129   *len = buf->ptr->len;
00130   return ERR_OK;
00131 }

void netbuf_delete struct netbuf buf  ) 
 

Definition at line 61 of file api_lib.c.

References memp_freep(), MEMP_NETBUF, NULL, netbuf::p, pbuf_free(), and netbuf::ptr.

Referenced by lwip_close(), lwip_recvfrom(), lwip_send(), netconn_delete(), serve_echo(), tcpecho_thread(), and udpecho_thread().

00062 {
00063   if(buf != NULL) {
00064     if(buf->p != NULL) {
00065       pbuf_free(buf->p);
00066       buf->p = buf->ptr = NULL;
00067     }
00068     memp_freep(MEMP_NETBUF, buf);
00069   }
00070 }

Here is the call graph for this function:

void netbuf_first struct netbuf buf  ) 
 

Definition at line 147 of file api_lib.c.

References netbuf::p, and netbuf::ptr.

00148 {
00149   buf->ptr = buf->p;
00150 }

void netbuf_free struct netbuf buf  ) 
 

Definition at line 88 of file api_lib.c.

References NULL, netbuf::p, pbuf_free(), and netbuf::ptr.

00089 {
00090   if(buf->p != NULL) {
00091     pbuf_free(buf->p);
00092   }
00093   buf->p = buf->ptr = NULL;
00094 }

Here is the call graph for this function:

struct ip_addr* netbuf_fromaddr struct netbuf buf  ) 
 

Definition at line 188 of file api_lib.c.

References netbuf::fromaddr.

Referenced by lwip_recvfrom().

00189 {
00190   return buf->fromaddr;
00191 }

u16_t netbuf_fromport struct netbuf buf  ) 
 

Definition at line 194 of file api_lib.c.

References netbuf::fromport.

Referenced by lwip_recvfrom().

00195 {
00196   return buf->fromport;
00197 }

u16_t netbuf_len struct netbuf buf  ) 
 

Definition at line 117 of file api_lib.c.

References netbuf::p, and pbuf::tot_len.

Referenced by lwip_recvfrom().

00118 {
00119   return buf->p->tot_len;
00120 }

struct netbuf* netbuf_new void   ) 
 

Definition at line 46 of file api_lib.c.

References memp_mallocp(), MEMP_NETBUF, and NULL.

Referenced by lwip_send(), and udpclient().

00047 {
00048   struct netbuf *buf;
00049 
00050   buf = memp_mallocp(MEMP_NETBUF);
00051   if(buf != NULL) {
00052     buf->p = NULL;
00053     buf->ptr = NULL;
00054     return buf;
00055   } else {
00056     return NULL;
00057   }
00058 }

Here is the call graph for this function:

s8_t netbuf_next struct netbuf buf  ) 
 

Definition at line 134 of file api_lib.c.

References pbuf::next, NULL, and netbuf::ptr.

Referenced by serve_echo(), and tcpecho_thread().

00135 {
00136   if(buf->ptr->next == NULL) {
00137     return -1;
00138   }
00139   buf->ptr = buf->ptr->next;
00140   if(buf->ptr->next == NULL) {
00141     return 1;
00142   }
00143   return 0;
00144 }

void netbuf_ref struct netbuf buf,
void *  dataptr,
u16_t  size
 

Definition at line 97 of file api_lib.c.

References pbuf::len, NULL, netbuf::p, pbuf::payload, pbuf_alloc(), pbuf_free(), PBUF_REF, PBUF_TRANSPORT, netbuf::ptr, pbuf::tot_len, and u16_t.

Referenced by lwip_send(), and udpclient().

00098 {
00099   if(buf->p != NULL) {
00100     pbuf_free(buf->p);
00101   }
00102   buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
00103   buf->p->payload = dataptr;
00104   buf->p->len = buf->p->tot_len = size;
00105   buf->ptr = buf->p;
00106 }

Here is the call graph for this function:

struct netconn* netconn_accept struct netconn conn  ) 
 

Definition at line 452 of file api_lib.c.

References netconn::acceptmbox, netconn::callback, conn, NETCONN_EVT_RCVMINUS, newconn, NULL, and sys_mbox_fetch().

Referenced by lwip_accept(), and tcpecho_thread().

00453 {
00454   struct netconn *newconn;
00455   
00456   if(conn == NULL) {
00457     return NULL;
00458   }
00459   
00460   sys_mbox_fetch(conn->acceptmbox, (void **)&newconn);
00461   /* Register event with callback */
00462   if (conn->callback)
00463       (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0);
00464   
00465   return newconn;
00466 }

Here is the call graph for this function:

err_t netconn_addr struct netconn conn,
struct ip_addr **  addr,
u16_t port
 

Definition at line 324 of file api_lib.c.

References conn, netconn::err, ERR_OK, NETCONN_TCP, NETCONN_UDP, NETCONN_UDPLITE, NETCONN_UDPNOCHKSUM, netconn::pcb, netconn::type, and u16_t.

Referenced by lwip_getsockname().

00326 {
00327   switch(conn->type) {
00328   case NETCONN_UDPLITE:
00329   case NETCONN_UDPNOCHKSUM:
00330   case NETCONN_UDP:
00331     *addr = &(conn->pcb.udp->local_ip);
00332     *port = conn->pcb.udp->local_port;
00333     break;
00334   case NETCONN_TCP:
00335     *addr = &(conn->pcb.tcp->local_ip);
00336     *port = conn->pcb.tcp->local_port;
00337     break;
00338   }
00339   return (conn->err = ERR_OK);
00340 }

err_t netconn_bind struct netconn conn,
struct ip_addr addr,
u16_t  port
 

Definition at line 343 of file api_lib.c.

References API_MSG_BIND, api_msg_post(), conn, netconn::err, ERR_MEM, ERR_VAL, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NETCONN_TCP, NULL, netconn::recvmbox, sys_mbox_fetch(), sys_mbox_new(), SYS_MBOX_NULL, netconn::type, and u16_t.

Referenced by lwip_bind(), tcp_client(), tcpecho_thread(), and udpecho_thread().

00345 {
00346   struct api_msg *msg;
00347 
00348   if(conn == NULL) {
00349     return ERR_VAL;
00350   }
00351 
00352   if(conn->type != NETCONN_TCP &&
00353      conn->recvmbox == SYS_MBOX_NULL) {
00354     if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
00355       return ERR_MEM;
00356     }
00357   }
00358   
00359   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00360     return (conn->err = ERR_MEM);
00361   }
00362   msg->type = API_MSG_BIND;
00363   msg->msg.conn = conn;
00364   msg->msg.msg.bc.ipaddr = addr;
00365   msg->msg.msg.bc.port = port;
00366   api_msg_post(msg);
00367   sys_mbox_fetch(conn->mbox, NULL);
00368   memp_freep(MEMP_API_MSG, msg);
00369   return conn->err;
00370 }

Here is the call graph for this function:

err_t netconn_close struct netconn conn  ) 
 

Definition at line 669 of file api_lib.c.

References API_MSG_CLOSE, api_msg_post(), conn, netconn::err, ERR_MEM, ERR_VAL, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NETCONN_CLOSE, NETCONN_NONE, NULL, netconn::sem, netconn::state, sys_mbox_fetch(), SYS_SEM_NULL, and sys_sem_wait().

Referenced by serve_echo().

00670 {
00671   struct api_msg *msg;
00672 
00673   if(conn == NULL) {
00674     return ERR_VAL;
00675   }
00676   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00677     return (conn->err = ERR_MEM);
00678   }
00679 
00680   conn->state = NETCONN_CLOSE;
00681  again:
00682   msg->type = API_MSG_CLOSE;
00683   msg->msg.conn = conn;
00684   api_msg_post(msg);
00685   sys_mbox_fetch(conn->mbox, NULL);
00686   if(conn->err == ERR_MEM &&
00687      conn->sem != SYS_SEM_NULL) {
00688     sys_sem_wait(conn->sem);
00689     goto again;
00690   }
00691   conn->state = NETCONN_NONE;
00692   memp_freep(MEMP_API_MSG, msg);
00693   return conn->err;
00694 }

Here is the call graph for this function:

err_t netconn_connect struct netconn conn,
struct ip_addr addr,
u16_t  port
 

Definition at line 374 of file api_lib.c.

References API_MSG_CONNECT, api_msg_post(), conn, netconn::err, ERR_MEM, ERR_VAL, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NULL, netconn::recvmbox, sys_mbox_fetch(), sys_mbox_new(), SYS_MBOX_NULL, and u16_t.

Referenced by lwip_connect(), lwip_sendto(), tcp_client(), and udpclient().

00376 {
00377   struct api_msg *msg;
00378   
00379   if(conn == NULL) {
00380     return ERR_VAL;
00381   }
00382 
00383 
00384   if(conn->recvmbox == SYS_MBOX_NULL) {
00385     if((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
00386       return ERR_MEM;
00387     }
00388   }
00389   
00390   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00391     return ERR_MEM;
00392   }
00393   msg->type = API_MSG_CONNECT;
00394   msg->msg.conn = conn;  
00395   msg->msg.msg.bc.ipaddr = addr;
00396   msg->msg.msg.bc.port = port;
00397   api_msg_post(msg);
00398   sys_mbox_fetch(conn->mbox, NULL);
00399   memp_freep(MEMP_API_MSG, msg);
00400   return conn->err;
00401 }

Here is the call graph for this function:

err_t netconn_delete struct netconn conn  ) 
 

Definition at line 240 of file api_lib.c.

References netconn::acceptmbox, API_MSG_DELCONN, api_msg_post(), conn, ERR_MEM, ERR_OK, netconn::mbox, MEMP_API_MSG, memp_free(), memp_freep(), memp_mallocp(), MEMP_NETCONN, netbuf_delete(), NETCONN_TCP, NULL, pbuf_free(), netconn::recvmbox, netconn::sem, sys_arch_mbox_fetch(), sys_mbox_fetch(), sys_mbox_free(), SYS_MBOX_NULL, sys_sem_free(), SYS_SEM_NULL, and netconn::type.

Referenced by cleanup_module(), lwip_accept(), lwip_close(), lwip_socket(), serve_echo(), and tcp_client().

00241 {
00242   struct api_msg *msg;
00243   void *mem;
00244   
00245   if(conn == NULL) {
00246     return ERR_OK;
00247   }
00248   
00249   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00250     return ERR_MEM;
00251   }
00252   
00253   msg->type = API_MSG_DELCONN;
00254   msg->msg.conn = conn;
00255   api_msg_post(msg);  
00256   sys_mbox_fetch(conn->mbox, NULL);
00257   memp_freep(MEMP_API_MSG, msg);
00258 
00259   /* Drain the recvmbox. */
00260   if(conn->recvmbox != SYS_MBOX_NULL) {
00261     while(sys_arch_mbox_fetch(conn->recvmbox, &mem, 1) != 0) {
00262       if(conn->type == NETCONN_TCP) {
00263         pbuf_free((struct pbuf *)mem);
00264       } else {
00265         netbuf_delete((struct netbuf *)mem);
00266       }
00267     }
00268     sys_mbox_free(conn->recvmbox);
00269     conn->recvmbox = SYS_MBOX_NULL;
00270   }
00271  
00272 
00273   /* Drain the acceptmbox. */
00274   if(conn->acceptmbox != SYS_MBOX_NULL) {
00275     while(sys_arch_mbox_fetch(conn->acceptmbox, &mem, 1) != 0) {
00276       netconn_delete((struct netconn *)mem);
00277     }
00278     
00279     sys_mbox_free(conn->acceptmbox);
00280     conn->acceptmbox = SYS_MBOX_NULL;
00281   }
00282 
00283   sys_mbox_free(conn->mbox);
00284   conn->mbox = SYS_MBOX_NULL;
00285   if(conn->sem != SYS_SEM_NULL) {
00286     sys_sem_free(conn->sem);
00287   }
00288   /*  conn->sem = SYS_SEM_NULL;*/
00289   memp_free(MEMP_NETCONN, conn);
00290   return ERR_OK;
00291 }

Here is the call graph for this function:

err_t netconn_disconnect struct netconn conn  ) 
 

Definition at line 404 of file api_lib.c.

References API_MSG_DISCONNECT, api_msg_post(), conn, netconn::err, ERR_MEM, ERR_VAL, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NULL, and sys_mbox_fetch().

Referenced by lwip_connect(), and lwip_sendto().

00405 {
00406   struct api_msg *msg;
00407   
00408   if(conn == NULL) {
00409     return ERR_VAL;
00410   }
00411 
00412   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00413     return ERR_MEM;
00414   }
00415   msg->type = API_MSG_DISCONNECT;
00416   msg->msg.conn = conn;  
00417   api_msg_post(msg);
00418   sys_mbox_fetch(conn->mbox, NULL);
00419   memp_freep(MEMP_API_MSG, msg);
00420   return conn->err;
00421 
00422 }

Here is the call graph for this function:

err_t netconn_err struct netconn conn  ) 
 

Definition at line 697 of file api_lib.c.

References conn, and netconn::err.

00698 {
00699   return conn->err;
00700 }

err_t netconn_listen struct netconn conn  ) 
 

Definition at line 425 of file api_lib.c.

References netconn::acceptmbox, API_MSG_LISTEN, api_msg_post(), conn, netconn::err, ERR_MEM, ERR_VAL, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NULL, sys_mbox_fetch(), sys_mbox_new(), and SYS_MBOX_NULL.

Referenced by lwip_listen(), and tcpecho_thread().

00426 {
00427   struct api_msg *msg;
00428 
00429   if(conn == NULL) {
00430     return ERR_VAL;
00431   }
00432 
00433   if(conn->acceptmbox == SYS_MBOX_NULL) {
00434     conn->acceptmbox = sys_mbox_new();
00435     if(conn->acceptmbox == SYS_MBOX_NULL) {
00436       return ERR_MEM;
00437     }
00438   }
00439   
00440   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00441     return (conn->err = ERR_MEM);
00442   }
00443   msg->type = API_MSG_LISTEN;
00444   msg->msg.conn = conn;
00445   api_msg_post(msg);
00446   sys_mbox_fetch(conn->mbox, NULL);
00447   memp_freep(MEMP_API_MSG, msg);
00448   return conn->err;
00449 }

Here is the call graph for this function:

struct netconn* netconn_new enum netconn_type  type  ) 
 

Definition at line 200 of file api_lib.c.

References netconn::acceptmbox, netconn::callback, conn, netconn::mbox, memp_freep(), memp_mallocp(), MEMP_NETCONN, NETCONN_NONE, NULL, netconn::pcb, netconn::recv_avail, netconn::recvmbox, netconn::sem, netconn::socket, netconn::state, sys_mbox_new(), SYS_MBOX_NULL, SYS_SEM_NULL, and netconn::type.

Referenced by netconn_new_with_callback(), tcp_client(), tcpecho_thread(), udpclient(), and udpecho_thread().

00201 {
00202   struct netconn *conn;
00203 
00204   conn = memp_mallocp(MEMP_NETCONN);
00205   if(conn == NULL) {
00206     return NULL;
00207   }
00208   conn->type = t;
00209   conn->pcb.tcp = NULL;
00210 
00211   if((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
00212     memp_freep(MEMP_NETCONN, conn);
00213     return NULL;
00214   }
00215   conn->recvmbox = SYS_MBOX_NULL;
00216   conn->acceptmbox = SYS_MBOX_NULL;
00217   conn->sem = SYS_SEM_NULL;
00218   conn->state = NETCONN_NONE;
00219   conn->socket = 0;
00220   conn->callback = 0;
00221   conn->recv_avail = 0;
00222   return conn;
00223 }

Here is the call graph for this function:

struct netconn* netconn_new_with_callback enum netconn_type  t,
void(*  callback)(struct netconn *, enum netconn_evt, u16_t len)
 

Definition at line 226 of file api_lib.c.

References netconn::callback, conn, netconn_new(), and u16_t.

Referenced by lwip_socket().

00228 {
00229     struct netconn *conn;
00230     
00231     /* get a netconn and then initialize callback pointer and socket */
00232     conn = netconn_new(t);
00233     if (conn)
00234         conn->callback = callback;
00235     return conn;
00236 }

Here is the call graph for this function:

err_t netconn_peer struct netconn conn,
struct ip_addr addr,
u16_t port
 

Definition at line 300 of file api_lib.c.

References conn, netconn::err, ERR_CONN, ERR_OK, NETCONN_TCP, NETCONN_UDP, NETCONN_UDPLITE, NETCONN_UDPNOCHKSUM, NULL, netconn::pcb, netconn::type, u16_t, and UDP_FLAGS_CONNECTED.

Referenced by lwip_accept(), lwip_getpeername(), and lwip_sendto().

00302 {
00303   switch(conn->type) {
00304   case NETCONN_UDPLITE:
00305   case NETCONN_UDPNOCHKSUM:
00306   case NETCONN_UDP:
00307     if (conn->pcb.udp == NULL ||
00308         ((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0))
00309      return ERR_CONN;
00310     *addr = (conn->pcb.udp->remote_ip);
00311     *port = conn->pcb.udp->remote_port;
00312     break;
00313   case NETCONN_TCP:
00314     if(conn->pcb.tcp == NULL)
00315       return ERR_CONN;
00316     *addr = (conn->pcb.tcp->remote_ip);
00317     *port = conn->pcb.tcp->remote_port;
00318     break;
00319   }
00320   return (conn->err = ERR_OK);
00321 }

struct netbuf* netconn_recv struct netconn conn  ) 
 

Definition at line 469 of file api_lib.c.

References API_LIB_DEBUG, api_msg_post(), API_MSG_RECV, netconn::callback, conn, DEBUGF, netconn::err, ERR_CONN, ERR_MEM, ERR_OK, len, LISTEN, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), MEMP_NETBUF, NETCONN_EVT_RCVMINUS, NETCONN_TCP, NULL, netconn::pcb, netconn::recv_avail, netconn::recvmbox, sys_mbox_fetch(), sys_mbox_free(), SYS_MBOX_NULL, netconn::type, and u16_t.

Referenced by lwip_recvfrom(), serve_echo(), tcpecho_thread(), and udpecho_thread().

00470 {
00471   struct api_msg *msg;
00472   struct netbuf *buf;
00473   struct pbuf *p;
00474   u16_t len;
00475     
00476   if(conn == NULL) {
00477     return NULL;
00478   }
00479   
00480   if(conn->recvmbox == SYS_MBOX_NULL) {
00481     conn->err = ERR_CONN;
00482     return NULL;
00483   }
00484 
00485   if(conn->err != ERR_OK) {
00486     return NULL;
00487   }
00488 
00489   if(conn->type == NETCONN_TCP) {
00490     if(conn->pcb.tcp->state == LISTEN) {
00491       conn->err = ERR_CONN;
00492       return NULL;
00493     }
00494 
00495 
00496     buf = memp_mallocp(MEMP_NETBUF);
00497 
00498     if(buf == NULL) {
00499       conn->err = ERR_MEM;
00500       return NULL;
00501     }
00502     
00503     sys_mbox_fetch(conn->recvmbox, (void **)&p);
00504 
00505     if (p != NULL)
00506     {
00507         len = p->tot_len;
00508         conn->recv_avail -= len;
00509     }
00510     else
00511         len = 0;
00512     
00513     /* Register event with callback */
00514       if (conn->callback)
00515         (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, len);
00516 
00517     /* If we are closed, we indicate that we no longer wish to recieve
00518        data by setting conn->recvmbox to SYS_MBOX_NULL. */
00519     if(p == NULL) {
00520       memp_freep(MEMP_NETBUF, buf);
00521       sys_mbox_free(conn->recvmbox);
00522       conn->recvmbox = SYS_MBOX_NULL;
00523       return NULL;
00524     }
00525 
00526     buf->p = p;
00527     buf->ptr = p;
00528     buf->fromport = 0;
00529     buf->fromaddr = NULL;
00530 
00531     /* Let the stack know that we have taken the data. */
00532     if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00533       conn->err = ERR_MEM;
00534       return buf;
00535     }
00536     msg->type = API_MSG_RECV;
00537     msg->msg.conn = conn;
00538     if(buf != NULL) {
00539       msg->msg.msg.len = buf->p->tot_len;
00540     } else {
00541       msg->msg.msg.len = 1;
00542     }
00543     api_msg_post(msg);
00544 
00545     sys_mbox_fetch(conn->mbox, NULL);
00546     memp_freep(MEMP_API_MSG, msg);
00547   } else {
00548     sys_mbox_fetch(conn->recvmbox, (void **)&buf);
00549         conn->recv_avail -= buf->p->tot_len;
00550     /* Register event with callback */
00551     if (conn->callback)
00552         (*conn->callback)(conn, NETCONN_EVT_RCVMINUS, buf->p->tot_len);
00553   }
00554 
00555   
00556 
00557     
00558   DEBUGF(API_LIB_DEBUG, ("netconn_recv: received %p (err %d)\n", (void *)buf, conn->err));
00559 
00560 
00561   return buf;
00562 }

Here is the call graph for this function:

err_t netconn_send struct netconn conn,
struct netbuf buf
 

Definition at line 565 of file api_lib.c.

References API_LIB_DEBUG, api_msg_post(), API_MSG_SEND, conn, DEBUGF, netconn::err, ERR_MEM, ERR_OK, ERR_VAL, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NULL, netbuf::p, sys_mbox_fetch(), and pbuf::tot_len.

Referenced by lwip_send(), and udpclient().

00566 {
00567   struct api_msg *msg;
00568 
00569   if(conn == NULL) {
00570     return ERR_VAL;
00571   }
00572 
00573   if(conn->err != ERR_OK) {
00574     return conn->err;
00575   }
00576 
00577   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00578     return (conn->err = ERR_MEM);
00579   }
00580 
00581   DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %d bytes\n", buf->p->tot_len));
00582   msg->type = API_MSG_SEND;
00583   msg->msg.conn = conn;
00584   msg->msg.msg.p = buf->p;
00585   api_msg_post(msg);
00586 
00587   sys_mbox_fetch(conn->mbox, NULL);
00588   memp_freep(MEMP_API_MSG, msg);
00589   return conn->err;
00590 }

Here is the call graph for this function:

enum netconn_type netconn_type struct netconn conn  ) 
 

Definition at line 294 of file api_lib.c.

References conn, and netconn::type.

00295 {
00296   return conn->type;
00297 }

err_t netconn_write struct netconn conn,
void *  dataptr,
u16_t  size,
u8_t  copy
 

Definition at line 593 of file api_lib.c.

References API_LIB_DEBUG, api_msg_post(), API_MSG_WRITE, conn, DEBUGF, netconn::err, ERR_MEM, ERR_OK, ERR_VAL, len, netconn::mbox, MEMP_API_MSG, memp_freep(), memp_mallocp(), NETCONN_NONE, NETCONN_TCP, NETCONN_WRITE, NULL, netconn::pcb, netconn::sem, netconn::state, sys_mbox_fetch(), sys_sem_free(), sys_sem_new(), SYS_SEM_NULL, sys_sem_wait(), tcp_sndbuf, netconn::type, u16_t, and u8_t.

Referenced by lwip_send(), and tcp_client().

00594 {
00595   struct api_msg *msg;
00596   u16_t len;
00597   
00598   if(conn == NULL) {
00599     return ERR_VAL;
00600   }
00601 
00602   if(conn->err != ERR_OK) {
00603     return conn->err;
00604   }
00605   
00606   if(conn->sem == SYS_SEM_NULL) {
00607     conn->sem = sys_sem_new(0);
00608     if(conn->sem == SYS_SEM_NULL) {
00609       return ERR_MEM;
00610     }
00611   }
00612 
00613   if((msg = memp_mallocp(MEMP_API_MSG)) == NULL) {
00614     return (conn->err = ERR_MEM);
00615   }
00616   msg->type = API_MSG_WRITE;
00617   msg->msg.conn = conn;
00618         
00619 
00620   conn->state = NETCONN_WRITE;
00621   while(conn->err == ERR_OK && size > 0) {
00622     msg->msg.msg.w.dataptr = dataptr;
00623     msg->msg.msg.w.copy = copy;
00624     
00625     if(conn->type == NETCONN_TCP) {
00626       if(tcp_sndbuf(conn->pcb.tcp) == 0) {
00627         sys_sem_wait(conn->sem);
00628         if(conn->err != ERR_OK) {
00629           goto ret;
00630         }
00631       }
00632       if(size > tcp_sndbuf(conn->pcb.tcp)) {
00633         /* We cannot send more than one send buffer's worth of data at a
00634            time. */
00635         len = tcp_sndbuf(conn->pcb.tcp);
00636       } else {
00637         len = size;
00638       }
00639     } else {
00640       len = size;
00641     }
00642     
00643     DEBUGF(API_LIB_DEBUG, ("netconn_write: writing %d bytes (%d)\n", len, copy));
00644     msg->msg.msg.w.len = len;
00645     api_msg_post(msg);
00646     sys_mbox_fetch(conn->mbox, NULL);    
00647     if(conn->err == ERR_OK) {
00648       dataptr = (void *)((char *)dataptr + len);
00649       size -= len;
00650     } else if(conn->err == ERR_MEM) {
00651       conn->err = ERR_OK;
00652       sys_sem_wait(conn->sem);
00653     } else {
00654       goto ret;
00655     }
00656   }
00657  ret:
00658   memp_freep(MEMP_API_MSG, msg);
00659   conn->state = NETCONN_NONE;
00660   if(conn->sem != SYS_SEM_NULL) {
00661     sys_sem_free(conn->sem);
00662     conn->sem = SYS_SEM_NULL;
00663   }
00664   
00665   return conn->err;
00666 }

Here is the call graph for this function:


Generated on Wed Jan 14 12:58:58 2004 for RTL-lwIP-0.4 by doxygen 1.3.4