* Receive callback function for RAW netconns. * Doesn't 'eat' the packet, only copies it and sends it to * conn->recvmbox * * @see raw.h (struct raw_pcb.recv) for parameters and return value */
| 156 | * @see raw.h (struct raw_pcb.recv) for parameters and return value |
| 157 | */ |
| 158 | static u8_t |
| 159 | recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p, |
| 160 | const ip_addr_t *addr) |
| 161 | { |
| 162 | struct pbuf *q; |
| 163 | struct netbuf *buf; |
| 164 | struct netconn *conn; |
| 165 | |
| 166 | LWIP_UNUSED_ARG(addr); |
| 167 | conn = (struct netconn *)arg; |
| 168 | |
| 169 | if ((conn != NULL) && NETCONN_MBOX_VALID(conn, &conn->recvmbox)) { |
| 170 | #if LWIP_SO_RCVBUF |
| 171 | int recv_avail; |
| 172 | SYS_ARCH_GET(conn->recv_avail, recv_avail); |
| 173 | if ((recv_avail + (int)(p->tot_len)) > conn->recv_bufsize) { |
| 174 | return 0; |
| 175 | } |
| 176 | #endif /* LWIP_SO_RCVBUF */ |
| 177 | /* copy the whole packet into new pbufs */ |
| 178 | q = pbuf_clone(PBUF_RAW, PBUF_RAM, p); |
| 179 | if (q != NULL) { |
| 180 | u16_t len; |
| 181 | buf = (struct netbuf *)memp_malloc(MEMP_NETBUF); |
| 182 | if (buf == NULL) { |
| 183 | pbuf_free(q); |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | buf->p = q; |
| 188 | buf->ptr = q; |
| 189 | ip_addr_copy(buf->addr, *ip_current_src_addr()); |
| 190 | buf->port = pcb->protocol; |
| 191 | |
| 192 | len = q->tot_len; |
| 193 | if (sys_mbox_trypost(&conn->recvmbox, buf) != ERR_OK) { |
| 194 | netbuf_delete(buf); |
| 195 | return 0; |
| 196 | } else { |
| 197 | #if LWIP_SO_RCVBUF |
| 198 | SYS_ARCH_INC(conn->recv_avail, len); |
| 199 | #endif /* LWIP_SO_RCVBUF */ |
| 200 | /* Register event with callback */ |
| 201 | API_EVENT(conn, NETCONN_EVT_RCVPLUS, len); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | return 0; /* do not eat the packet */ |
| 207 | } |
| 208 | #endif /* LWIP_RAW*/ |
| 209 | |
| 210 | #if LWIP_UDP |
nothing calls this directly
no test coverage detected