API参考
载入中...
搜索中...
未找到
bsl_uio.h
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 * http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
21
22#ifndef BSL_UIO_H
23#define BSL_UIO_H
24
25#include <stddef.h>
26#include <stdint.h>
27#include <stdbool.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
37typedef struct UIO_ControlBlock BSL_UIO;
38
39typedef int32_t BSL_UIO_InfoCb(BSL_UIO *, int32_t, int32_t);
40
41
42typedef int32_t (*BslUioWriteCb)(BSL_UIO *uio, const void *buf, uint32_t len, uint32_t *writeLen);
43typedef int32_t (*BslUioReadCb)(BSL_UIO *uio, void *buf, uint32_t len, uint32_t *readLen);
44typedef int32_t (*BslUioCtrlCb)(BSL_UIO *uio, int32_t cmd, int32_t larg, void *parg);
45typedef int32_t (*BslUioCreateCb)(BSL_UIO *uio);
46typedef int32_t (*BslUioDestroyCb)(BSL_UIO *uio);
47typedef int32_t (*BslUioPutsCb)(BSL_UIO *uio, const char *buf, uint32_t *writeLen);
48typedef int32_t (*BslUioGetsCb)(BSL_UIO *uio, char *buf, uint32_t *readLen);
49typedef int32_t (*BslUioCbCtrlCb)(BSL_UIO *uio, int cmd, BSL_UIO_InfoCb *callback);
50
51typedef struct BSL_UIO_MethodStruct BSL_UIO_Method;
52
57typedef enum {
58 BSL_UIO_TCP,
59 BSL_UIO_UDP,
60 BSL_UIO_SCTP,
61 BSL_UIO_MEM,
62 BSL_UIO_FILE,
63 BSL_UIO_BUFFER,
64 BSL_UIO_UNKNOWN, /* Unknown protocol should not appear */
65
66 BSL_UIO_EXTEND = 10000, /* extension value */
68
69#define IS_TRANSTYPE_DATAGRAM(transportType) ((transportType) == BSL_UIO_SCTP || (transportType) == BSL_UIO_UDP)
70
76typedef struct {
77 uint16_t shareKeyId;
78 uint16_t authKeySize;
79 const uint8_t *authKey;
81
86typedef void (*BSL_UIO_USERDATA_FREE_FUNC)(void *);
87
93typedef enum {
94 /* The cmd(0-0x99) used by the abstraction layer and the uio
95 * implemented by the user cannot reuse these values. */
96
97 /* Public use 0x000 */
98 /* larg equals the length of array, parg is a pointer type array */
99 BSL_UIO_SET_PEER_IP_ADDR = 0x000,
100 /* larg equals the length of BSL_UIO_CtrlGetPeerIpAddrParam structure,
101 * parg is a pointer type BSL_UIO_CtrlGetPeerIpAddrParam
102 */
103 BSL_UIO_GET_PEER_IP_ADDR,
104 /* larg equals the length of 32-bit integer, parg is a pointer type 32-bit integer */
105 BSL_UIO_SET_FD,
106 /* larg equals the length of 32-bit integer, parg is a pointer type 32-bit integer */
107 BSL_UIO_GET_FD,
108 /* larg equals the length of 64-bit integer, parg is a pointer type 64-bit integer */
109 BSL_UIO_PENDING,
110 /* not need to set larg and parg. the default values are 0 and null */
111 BSL_UIO_FLUSH,
112 /* larg equals the length of 64-bit integer, parg is a pointer type 64-bit integer */
113 BSL_UIO_WPENDING,
114 /* larg equals the length of 64-bit integer, parg is a pointer type 64-bit integer */
115 BSL_UIO_SEEK,
116 /* not need to set larg and parg. the default values are 0 and null */
117 BSL_UIO_RESET,
118 /* larg equals the length of bool, parg is a pointer type bool */
119 BSL_UIO_GET_INIT,
120 /* larg equals the length of 64-bit integer, parg is a pointer type 64-bit integer */
121 BSL_UIO_GET_WRITE_NUM,
122 /* larg equals the length of 64-bit integer, parg is a pointer type 64-bit integer */
123 BSL_UIO_GET_READ_NUM,
124 /* larg equals the length of 32-bit integer, parg is a pointer type 32-bit integer */
125 BSL_UIO_GET_PTO_LEN,
126 BSL_UIO_INFO,
127 BIO_UIO_SET_CALLBACK,
128 BSL_UIO_SET_CONNECT,
129 BSL_UIO_GET_CONNECT,
130 BSL_UIO_SET_NOBLOCK,
131 BSL_UIO_DO_HANDSHAKE,
132 BSL_UIO_SET_CTX,
133 BSL_UIO_GET_CTX,
134 BSL_UIO_SET_SSL_RENEGOTIATE_TIMEOUT,
135 BSL_UIO_SET_SSL_RENEGOTIATE_BYTES,
136 BSL_UIO_UDP_SET_CONNECTED,
137 BSL_UIO_SET_BUFFER_SIZE,
138 BSL_UIO_UDP_GET_MTU_OVERHEAD,
139 BSL_UIO_UDP_QUERY_MTU,
140 BSL_UIO_UDP_MTU_EXCEEDED,
141 BSL_UIO_CIPHER_IS_FINISHED,
142 BSL_UIO_SET_CONNECT_MODE,
143 BSL_UIO_SET_ACCEPT,
144 BSL_UIO_GET_ACCEPT,
145 BSL_UIO_SET_BIND_MODE,
146 BSL_UIO_GET_BIND_MODE,
147 BSL_UIO_APPEND,
148
149 /* SCTP uses 0x3XX */
165 BSL_UIO_SCTP_GET_SEND_STREAM_ID,
166 /* larg equals the length of unsigned 16-bit integer, parg is a pointer type unsigned 16-bit integer */
167 BSL_UIO_SCTP_SET_APP_STREAM_ID,
168 /* larg equals the length of bool, parg is a pointer type bool */
169 BSL_UIO_SCTP_MASK_APP_MESSAGE,
170 /* larg is a func callback type BSL_UIO_METHOD_TYPE, parg is a pointer type func callback */
171 BSL_UIO_SCTP_SET_CALLBACK,
172
173 /* MEMʹÓÃ0x4XX */
174 /* larg equals the length of array, parg is a pointer type array */
175 BSL_UIO_MEM_NEW_BUF = 0x400,
176 /* larg equals the length of pointer, parg is a pointer's pointer type BSL_BufMem */
177 BSL_UIO_MEM_GET_PTR,
178 /* larg equals the length of 32-bit integer, parg is a pointer type 32-bit integer */
179 BSL_UIO_MEM_SET_EOF,
180 /* larg equals the length of 32-bit integer, parg is a pointer type 32-bit integer */
181 BSL_UIO_MEM_GET_EOF,
182 /* larg equals the length of BSL_UIO_CtrlGetInfoParam, parg is a pointer type BSL_UIO_CtrlGetInfoParam */
183 BSL_UIO_MEM_GET_INFO,
184
185 /* FILEʹÓÃ0x5xx */
186 /* larg is the mode for opening a file, parg is a pointer type string */
187 BSL_UIO_FILE_OPEN = 0x500,
188 /* larg is of the Boolean type and is used to indicate whether the handle is closed with the release of uio,
189 * parg is a pointer type file */
190 BSL_UIO_FILE_PTR,
191 BSL_UIO_FILE_GET_EOF,
192 BSL_UIO_FILE_SEEK,
193 BSL_UIO_FILE_TELL,
194 BSL_UIO_FILE_GET_PTR,
195
196 /* FDʹÓÃ0x6xx */
197 /* larg equals the length of 64-bit integer, parg is a pointer type 64-bit integer */
198
199 BSL_UIO_FD_GET_INFO = 0x600,
200
201 /* Pair uses 0x7xx */
202 BSL_UIO_PAIR_MAKE = 0x700,
203 BSL_UIO_PAIR_SET_BUFFER_SIZE,
204 BSL_UIO_PAIR_GET_BUFFER_SIZE,
205
206 /* TTO uses 0x8xx */
207 BSL_UIO_TTO_SET_READ_CB = 0x800,
208 BSL_UIO_TTO_SET_WRITE_CB,
209 BSL_UIO_TTO_SET_READ_APP_DATA,
210 BSL_UIO_TTO_SET_WRITE_APP_DATA,
211
212 /* DTO uses 0x10xx */
213 BSL_UIO_DTO_SET_KEY = 0x1001,
214 BSL_UIO_DTO_SET_EPOCH_SEQUENCE,
216
217typedef enum {
218 BSL_UIO_CREATE_CB,
219 BSL_UIO_DESTROY_CB,
220 BSL_UIO_WRITE_CB,
221 BSL_UIO_READ_CB,
222 BSL_UIO_CTRL_CB,
223 BSL_UIO_PUTS_CB,
224 BSL_UIO_GETS_CB,
225} BSL_UIO_METHOD_TYPE;
226
227typedef struct {
228 uint8_t *addr;
229 uint32_t size;
231
232#define BSL_UIO_FILE_READ 0x02
233#define BSL_UIO_FILE_WRITE 0x04
234#define BSL_UIO_FILE_APPEND 0x08
235#define BSL_UIO_FILE_TEXT 0x10
236
237#define BSL_UIO_FLAGS_READ 0x01
238#define BSL_UIO_FLAGS_WRITE 0x02
239#define BSL_UIO_FLAGS_IO_SPECIAL 0x04
240#define BSL_UIO_FLAGS_RWS (BSL_UIO_FLAGS_READ | BSL_UIO_FLAGS_WRITE | BSL_UIO_FLAGS_IO_SPECIAL)
241#define BSL_UIO_FLAGS_SHOULD_RETRY 0x08
242
243#define BSL_UIO_FLAGS_MEM_READ_ONLY 0x10 /* This flag can be set only by uio_mem */
244
245#define BSL_UIO_FLAGS_BASE64_NO_NEWLINE 0x20
246#define BSL_UIO_FLAGS_BASE64_PEM 0x40
247
248
249
256BSL_UIO_Method *BSL_UIO_NewMethod(void);
257
267int32_t BSL_UIO_SetMethodType(BSL_UIO_Method *meth, BSL_UIO_TransportType type);
268
279int32_t BSL_UIO_SetMethod(BSL_UIO_Method *meth, int32_t type, void *func);
280
288void BSL_UIO_FreeMethod(BSL_UIO_Method *meth);
289
296const BSL_UIO_Method *BSL_UIO_MemMethod(void);
297
304const BSL_UIO_Method *BSL_UIO_FileMethod(void);
305
312const BSL_UIO_Method *BSL_UIO_SctpMethod(void);
313
320const BSL_UIO_Method *BSL_UIO_TcpMethod(void);
321
328const BSL_UIO_Method *BSL_UIO_UdpMethod(void);
329
336const BSL_UIO_Method *BSL_UIO_BufferMethod(void);
337
346BSL_UIO *BSL_UIO_New(const BSL_UIO_Method *method);
347
355
370int32_t BSL_UIO_Write(BSL_UIO *uio, const void *data, uint32_t len, uint32_t *writeLen);
371
386int32_t BSL_UIO_Read(BSL_UIO *uio, void *data, uint32_t len, uint32_t *readLen);
387
441int32_t BSL_UIO_Ctrl(BSL_UIO *uio, int32_t cmd, int32_t larg, void *parg);
442
456int32_t BSL_UIO_Puts(BSL_UIO *uio, const char *buf, uint32_t *writeLen);
457
471int32_t BSL_UIO_Gets(BSL_UIO *uio, char *buf, uint32_t *readLen);
472
480void BSL_UIO_SetInit(BSL_UIO *uio, bool init);
481
490
501
516int32_t BSL_UIO_SetUserData(BSL_UIO *uio, void *data);
517
530
542void *BSL_UIO_GetUserData(const BSL_UIO *uio);
543
553
563
571const BSL_UIO_Method *BSL_UIO_GetMethod(const BSL_UIO *uio);
572
580void *BSL_UIO_GetCtx(const BSL_UIO *uio);
581
589void BSL_UIO_SetCtx(BSL_UIO *uio, void *ctx);
590
598void BSL_UIO_SetFD(BSL_UIO *uio, int fd);
599
609int32_t BSL_UIO_SetFlags(BSL_UIO *uio, uint32_t flags);
610
620int32_t BSL_UIO_ClearFlags(BSL_UIO *uio, uint32_t flags);
621
632uint32_t BSL_UIO_TestFlags(const BSL_UIO *uio, uint32_t flags, uint32_t *out);
633
644int32_t BSL_UIO_UpRef(BSL_UIO *uio);
645
656int32_t BSL_UIO_Append(BSL_UIO *uio, BSL_UIO *tail);
657
667
677
686
687#ifdef __cplusplus
688}
689#endif
690
691#endif // BSL_UIO_H
struct UIO_ControlBlock BSL_UIO
UIO module control structure
定义 bsl_uio.h:37
int32_t BSL_UIO_SetFlags(BSL_UIO *uio, uint32_t flags)
Set the UIO object flag.
int32_t BSL_UIO_Write(BSL_UIO *uio, const void *data, uint32_t len, uint32_t *writeLen)
Write data to the UIO object
int32_t BSL_UIO_SetUserData(BSL_UIO *uio, void *data)
Set the user data in the UIO object
int32_t BSL_UIO_SetMethodType(BSL_UIO_Method *meth, BSL_UIO_TransportType type)
set uio method type
void BSL_UIO_FreeMethod(BSL_UIO_Method *meth)
free uio Method
const BSL_UIO_Method * BSL_UIO_MemMethod(void)
obtain the default MEM UIO
const BSL_UIO_Method * BSL_UIO_GetMethod(const BSL_UIO *uio)
Method for obtaining the UIO
int32_t BSL_UIO_Puts(BSL_UIO *uio, const char *buf, uint32_t *writeLen)
Write a string to the UIO object.
BSL_UIO_Method * BSL_UIO_NewMethod(void)
Creating uio method structure
void BSL_UIO_SetIsUnderlyingClosedByUio(BSL_UIO *uio, bool close)
Set whether resources associated with the UIO are closed by the UIO.
BSL_UIO_CtrlParameter
BSL_UIO_CtrlParameter controls the I/O callback function. Hitls notifies the user of the function to ...
定义 bsl_uio.h:93
const BSL_UIO_Method * BSL_UIO_FileMethod(void)
obtain the default FILE UIO method
int32_t BSL_UIO_SetUserDataFreeFunc(BSL_UIO *uio, BSL_UIO_USERDATA_FREE_FUNC userDataFreeFunc)
Release the user data set in the UIO object.
int32_t BSL_UIO_Read(BSL_UIO *uio, void *data, uint32_t len, uint32_t *readLen)
Read data from the UIO object.
int32_t BSL_UIO_SetMethod(BSL_UIO_Method *meth, int32_t type, void *func)
set uio method callback
BSL_UIO * BSL_UIO_New(const BSL_UIO_Method *method)
Create a UIO object
void BSL_UIO_Free(BSL_UIO *uio)
Release the UIO object.
int32_t BSL_UIO_ClearFlags(BSL_UIO *uio, uint32_t flags)
Clear the UIO object flag
int32_t BSL_UIO_UpRef(BSL_UIO *uio)
Set the value of uio reference counting to 1
int32_t BSL_UIO_Ctrl(BSL_UIO *uio, int32_t cmd, int32_t larg, void *parg)
Process specific UIO implementations by cmd
BSL_UIO * BSL_UIO_Next(BSL_UIO *uio)
Obtain the next UIO object in the chain.
const BSL_UIO_Method * BSL_UIO_UdpMethod(void)
obtain the default UDP UIO method
int32_t BSL_UIO_Append(BSL_UIO *uio, BSL_UIO *tail)
Add a UIO object to the tail of the chain.
void * BSL_UIO_GetCtx(const BSL_UIO *uio)
Obtain the implementation-related context.
void BSL_UIO_FreeChain(BSL_UIO *uio)
Release UIO object b and its subsequent chains.
bool BSL_UIO_GetUioChainTransportType(BSL_UIO *uio, const BSL_UIO_TransportType uioType)
Obtain the UIO transmission protocol type
void BSL_UIO_SetCtx(BSL_UIO *uio, void *ctx)
Set the implementation-related context.
BSL_UIO_TransportType
Transmission protocol enumeration
定义 bsl_uio.h:57
uint32_t BSL_UIO_TestFlags(const BSL_UIO *uio, uint32_t flags, uint32_t *out)
Check the UIO object flag
void(* BSL_UIO_USERDATA_FREE_FUNC)(void *)
userData release function
定义 bsl_uio.h:86
int32_t BSL_UIO_Gets(BSL_UIO *uio, char *buf, uint32_t *readLen)
Reads a string from the UIO object
void BSL_UIO_SetInit(BSL_UIO *uio, bool init)
Set the UIO init.
const BSL_UIO_Method * BSL_UIO_SctpMethod(void)
obtain the default SCTP UIO
BSL_UIO * BSL_UIO_PopCurrent(BSL_UIO *uio)
Pop UIO object from the chain.
void * BSL_UIO_GetUserData(const BSL_UIO *uio)
Obtain the user data in the UIO object.
BSL_UIO_TransportType BSL_UIO_GetTransportType(const BSL_UIO *uio)
Obtain the UIO transmission protocol type
const BSL_UIO_Method * BSL_UIO_TcpMethod(void)
obtain the default TCP UIO method
const BSL_UIO_Method * BSL_UIO_BufferMethod(void)
obtain the default buffer UIO
void BSL_UIO_SetFD(BSL_UIO *uio, int fd)
Set the fd of the UIO object
bool BSL_UIO_GetIsUnderlyingClosedByUio(const BSL_UIO *uio)
Obtains whether resources associated with the UIO are closed by the UIO.
@ BSL_UIO_SCTP_ACTIVE_AUTH_SHARED_KEY
定义 bsl_uio.h:153
@ BSL_UIO_SCTP_RECV_BUFF_IS_EMPTY
定义 bsl_uio.h:160
@ BSL_UIO_SCTP_SND_BUFF_IS_EMPTY
定义 bsl_uio.h:156
@ BSL_UIO_SCTP_CHECK_PEER_AUTH
定义 bsl_uio.h:150
@ BSL_UIO_SCTP_DEL_PRE_AUTH_SHARED_KEY
定义 bsl_uio.h:155
@ BSL_UIO_SCTP_ADD_AUTH_SHARED_KEY
定义 bsl_uio.h:151
定义 bsl_uio.h:227
Sctp auth key, hitls Use the BSL_UIO_Method.ctrl method to transfer the BSL_UIO_SCTP_ADD_AUTH_SHARED_...
定义 bsl_uio.h:76