• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TLS_NETCONN_H
17 #define TLS_NETCONN_H
18 
19 #include "tls_common.h"
20 #include "list.h"
21 #include "wm_socket.h"
22 #include "arch/sys_arch.h"
23 #include "wm_netif.h"
24 
25 #define TLS_NETCONN_TCP       0
26 #define TLS_NETCONN_UDP       1
27 
28 #define RAW_SOCKET_USE_CUSTOM_PBUF  LWIP_SUPPORT_CUSTOM_PBUF
29 
30 #define CONN_SEM_NOT_FREE       1
31 
32  /* A netconn descriptor */
33 struct tls_netconn {
34     struct dl_list list;
35     struct tls_socket_desc *skd;
36     u8        skt_num;
37     bool      used;
38 
39  /* client or server mode */
40     bool      client;
41     ip_addr_t addr;
42     u16       port;
43     u16       localport;
44     u16       proto;
45  /* the lwIP internal protocol control block */
46     union {
47         struct ip_pcb  *ip;
48         struct tcp_pcb *tcp;
49         struct udp_pcb *udp;
50         struct raw_pcb *raw;
51     } pcb;
52     bool   write_state;
53     u16    write_offset;
54     struct tls_net_msg *current_msg;
55     u8     tcp_connect_cnt;
56     u8     state;
57     err_t  last_err;
58 #if !CONN_SEM_NOT_FREE
59     sys_sem_t op_completed;
60 #endif
61     u32 idle_time;
62 };
63 
64 struct tls_net_msg {
65     struct dl_list list;
66     void *dataptr;
67     struct pbuf *p;
68     ip_addr_t addr;
69     u16       port;
70     u32   len;
71     u32   write_offset;
72     err_t err;
73     int skt_no;
74 };
75 
76 #if (RAW_SOCKET_USE_CUSTOM_PBUF)
77 struct raw_sk_pbuf_custom {
78     /** 'base class' */
79     struct pbuf_custom pc;
80     /** pointer to the original pbuf that is referenced */
81     struct pbuf *original;
82     /* custom pbuf free function used */
83     void *conn;
84     void *pcb;
85 };
86 #endif
87 
88 int tls_net_init(void);
89 struct tls_netconn *tls_net_get_socket(u8 socket);
90 
91 #endif /* end of TLS_NETCONN_H */
92 
93