ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 47:9e361da97763 1 // Copyright 2017 Baidu Inc. All Rights Reserved.
TMBOY 47:9e361da97763 2 // Author: Su Hao (suhao@baidu.com)
TMBOY 47:9e361da97763 3 //
TMBOY 47:9e361da97763 4 // Description: Define the adapter for networks.
TMBOY 47:9e361da97763 5
TMBOY 47:9e361da97763 6 #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_TRANSPORT_H
TMBOY 47:9e361da97763 7 #define BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_TRANSPORT_H
TMBOY 47:9e361da97763 8
TMBOY 47:9e361da97763 9 #include "baidu_ca_types.h"
TMBOY 47:9e361da97763 10 #include "baidu_ca.h"
TMBOY 47:9e361da97763 11
TMBOY 47:9e361da97763 12 #define BCA_READ_FOREVER ((bca_u32_t)-1)
TMBOY 47:9e361da97763 13
TMBOY 47:9e361da97763 14 /*
TMBOY 47:9e361da97763 15 * The handler operate transfer.
TMBOY 47:9e361da97763 16 */
TMBOY 47:9e361da97763 17 typedef void* bca_trans_handler;
TMBOY 47:9e361da97763 18
TMBOY 47:9e361da97763 19 typedef struct _bca_trans_s {
TMBOY 47:9e361da97763 20 bca_socket_t ctx;
TMBOY 47:9e361da97763 21 bca_context secure;
TMBOY 47:9e361da97763 22 bca_context soc_context;
TMBOY 47:9e361da97763 23 void* cert;
TMBOY 47:9e361da97763 24 bca_size_t cert_len;
TMBOY 47:9e361da97763 25 bca_u32_t read_timeout;
TMBOY 47:9e361da97763 26 bca_addr_t addr;
TMBOY 47:9e361da97763 27 } bca_trans_t, *bca_trans_ptr;
TMBOY 47:9e361da97763 28
TMBOY 47:9e361da97763 29 /*
TMBOY 47:9e361da97763 30 * Acquire the handler.
TMBOY 47:9e361da97763 31 *
TMBOY 47:9e361da97763 32 * @Param hdlr, in, the global context for baidu ca
TMBOY 47:9e361da97763 33 * @Param flag, in, the flag mark the transport properties, see in ${link bca_trans_flag_e}
TMBOY 47:9e361da97763 34 * @Param ctx, in, the socket context for user
TMBOY 47:9e361da97763 35 * @Return bca_trans_handler, the transport context
TMBOY 47:9e361da97763 36 */
TMBOY 47:9e361da97763 37 BCA_INT bca_trans_handler bca_trans_acquire(bca_context ctx);
TMBOY 47:9e361da97763 38
TMBOY 47:9e361da97763 39 /*
TMBOY 47:9e361da97763 40 * Set the public key or certificate.
TMBOY 47:9e361da97763 41 *
TMBOY 47:9e361da97763 42 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 43 * @Param data, in, the content of the public key or certificate
TMBOY 47:9e361da97763 44 * @Param size, in, the size of the data
TMBOY 47:9e361da97763 45 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 46 */
TMBOY 47:9e361da97763 47 BCA_INT bca_status_t bca_trans_set_pk(bca_trans_handler hdlr,
TMBOY 47:9e361da97763 48 const void* data,
TMBOY 47:9e361da97763 49 bca_size_t size);
TMBOY 47:9e361da97763 50
TMBOY 47:9e361da97763 51 /*
TMBOY 47:9e361da97763 52 * Set the timeout for receiving data.
TMBOY 47:9e361da97763 53 *
TMBOY 47:9e361da97763 54 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 55 * @Param timeout, in, the recv data timeout interval
TMBOY 47:9e361da97763 56 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 57 */
TMBOY 47:9e361da97763 58 BCA_INT bca_status_t bca_trans_set_read_timeout(bca_trans_handler hdlr,
TMBOY 47:9e361da97763 59 bca_u32_t timeout);
TMBOY 47:9e361da97763 60
TMBOY 47:9e361da97763 61 /*
TMBOY 47:9e361da97763 62 * Connect to the host.
TMBOY 47:9e361da97763 63 *
TMBOY 47:9e361da97763 64 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 65 * @Param addr, in, the target address infomations
TMBOY 47:9e361da97763 66 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 67 */
TMBOY 47:9e361da97763 68 BCA_INT bca_status_t bca_trans_connect(bca_trans_handler hdlr,
TMBOY 47:9e361da97763 69 const bca_addr_t* addr);
TMBOY 47:9e361da97763 70
TMBOY 47:9e361da97763 71 /*
TMBOY 47:9e361da97763 72 * Send data.
TMBOY 47:9e361da97763 73 *
TMBOY 47:9e361da97763 74 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 75 * @Param data, in, the data will be sent
TMBOY 47:9e361da97763 76 * @Param size, in, the data size
TMBOY 47:9e361da97763 77 * @Param addr, in, the target address infomations
TMBOY 47:9e361da97763 78 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 79 */
TMBOY 47:9e361da97763 80 BCA_INT bca_status_t bca_trans_send(bca_trans_handler hdlr,
TMBOY 47:9e361da97763 81 const void* data,
TMBOY 47:9e361da97763 82 bca_size_t size,
TMBOY 47:9e361da97763 83 const bca_addr_t* addr);
TMBOY 47:9e361da97763 84
TMBOY 47:9e361da97763 85 /*
TMBOY 47:9e361da97763 86 * Receive data.
TMBOY 47:9e361da97763 87 *
TMBOY 47:9e361da97763 88 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 89 * @Param data, out, the data will be read
TMBOY 47:9e361da97763 90 * @Param size, in, the data size
TMBOY 47:9e361da97763 91 * @Param addr, out, the target address infomations
TMBOY 47:9e361da97763 92 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 93 */
TMBOY 47:9e361da97763 94 BCA_INT bca_status_t bca_trans_recv(bca_trans_handler hdlr,
TMBOY 47:9e361da97763 95 void* data,
TMBOY 47:9e361da97763 96 bca_size_t size,
TMBOY 47:9e361da97763 97 bca_addr_t* addr);
TMBOY 47:9e361da97763 98
TMBOY 47:9e361da97763 99 /*
TMBOY 47:9e361da97763 100 * Disconnect from the remote host.
TMBOY 47:9e361da97763 101 *
TMBOY 47:9e361da97763 102 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 103 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 104 */
TMBOY 47:9e361da97763 105 BCA_INT bca_status_t bca_trans_close(bca_trans_handler hdlr);
TMBOY 47:9e361da97763 106
TMBOY 47:9e361da97763 107 /*
TMBOY 47:9e361da97763 108 * Release the handler.
TMBOY 47:9e361da97763 109 *
TMBOY 47:9e361da97763 110 * @Param hdlr, in, the context for the transport
TMBOY 47:9e361da97763 111 * @Return bca_status_t, the operation result
TMBOY 47:9e361da97763 112 */
TMBOY 47:9e361da97763 113 BCA_INT bca_status_t bca_trans_release(bca_trans_handler hdlr);
TMBOY 47:9e361da97763 114
TMBOY 47:9e361da97763 115 #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_TRANSPORT_H