* Create a new pcb of a specific type. * Called from lwip_netconn_do_newconn(). * * @param msg the api_msg describing the connection type */
| 606 | * @param msg the api_msg describing the connection type |
| 607 | */ |
| 608 | static void |
| 609 | pcb_new(struct api_msg *msg) |
| 610 | { |
| 611 | enum lwip_ip_addr_type iptype = IPADDR_TYPE_V4; |
| 612 | |
| 613 | LWIP_ASSERT("pcb_new: pcb already allocated", msg->conn->pcb.tcp == NULL); |
| 614 | |
| 615 | #if LWIP_IPV6 && LWIP_IPV4 |
| 616 | /* IPv6: Dual-stack by default, unless netconn_set_ipv6only() is called */ |
| 617 | if (NETCONNTYPE_ISIPV6(netconn_type(msg->conn))) { |
| 618 | iptype = IPADDR_TYPE_ANY; |
| 619 | } |
| 620 | #endif |
| 621 | |
| 622 | /* Allocate a PCB for this connection */ |
| 623 | switch (NETCONNTYPE_GROUP(msg->conn->type)) { |
| 624 | #if LWIP_RAW |
| 625 | case NETCONN_RAW: |
| 626 | msg->conn->pcb.raw = raw_new_ip_type(iptype, msg->msg.n.proto); |
| 627 | if (msg->conn->pcb.raw != NULL) { |
| 628 | #if LWIP_IPV6 |
| 629 | /* ICMPv6 packets should always have checksum calculated by the stack as per RFC 3542 chapter 3.1 */ |
| 630 | if (NETCONNTYPE_ISIPV6(msg->conn->type) && msg->conn->pcb.raw->protocol == IP6_NEXTH_ICMP6) { |
| 631 | msg->conn->pcb.raw->chksum_reqd = 1; |
| 632 | msg->conn->pcb.raw->chksum_offset = 2; |
| 633 | } |
| 634 | #endif /* LWIP_IPV6 */ |
| 635 | raw_recv(msg->conn->pcb.raw, recv_raw, msg->conn); |
| 636 | } |
| 637 | break; |
| 638 | #endif /* LWIP_RAW */ |
| 639 | #if LWIP_UDP |
| 640 | case NETCONN_UDP: |
| 641 | msg->conn->pcb.udp = udp_new_ip_type(iptype); |
| 642 | if (msg->conn->pcb.udp != NULL) { |
| 643 | #if LWIP_UDPLITE |
| 644 | if (NETCONNTYPE_ISUDPLITE(msg->conn->type)) { |
| 645 | udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_UDPLITE); |
| 646 | } |
| 647 | #endif /* LWIP_UDPLITE */ |
| 648 | if (NETCONNTYPE_ISUDPNOCHKSUM(msg->conn->type)) { |
| 649 | udp_setflags(msg->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); |
| 650 | } |
| 651 | udp_recv(msg->conn->pcb.udp, recv_udp, msg->conn); |
| 652 | } |
| 653 | break; |
| 654 | #endif /* LWIP_UDP */ |
| 655 | #if LWIP_TCP |
| 656 | case NETCONN_TCP: |
| 657 | msg->conn->pcb.tcp = tcp_new_ip_type(iptype); |
| 658 | if (msg->conn->pcb.tcp != NULL) { |
| 659 | setup_tcp(msg->conn); |
| 660 | } |
| 661 | break; |
| 662 | #endif /* LWIP_TCP */ |
| 663 | default: |
| 664 | /* Unsupported netconn type, e.g. protocol disabled */ |
| 665 | msg->err = ERR_VAL; |
no test coverage detected