coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, void *handle, SecureConnectionMode mode, send_cb *socket_cb, receive_cb *receive_data_cb, start_timer_cb *timer_start_cb, timer_status_cb *timer_stat_cb) { if (socket_cb == NULL || receive_data_cb == NULL || timer_start_cb == NULL || timer_stat_cb == NULL) { return NULL; } coap_security_t *this = ns_dyn_mem_alloc(sizeof(coap_security_t)); if( !this ){ return NULL; } memset(this, 0, sizeof(coap_security_t)); if (-1 == coap_security_handler_init(this)) { ns_dyn_mem_free(this); return NULL; } this->_handle = handle; this->_conn_mode = mode; memset(this->_pw, 0, 64); this->_pw_len = 0; this->_socket_id = socket_id; this->_timer_id = timer_id; this->_send_cb = socket_cb; this->_receive_cb = receive_data_cb; this->_start_timer_cb = timer_start_cb; this->_timer_status_cb = timer_stat_cb; return this; }
coap_security_t *coap_security_create(int8_t socket_id, int8_t timer_id, uint8_t *address_ptr, uint16_t port, SecureConnectionMode mode, send_cb *send_cb, receive_cb *receive_cb, start_timer_cb *start_timer_cb, timer_status_cb *timer_status_cb) { if( !address_ptr || send_cb == NULL || receive_cb == NULL || start_timer_cb == NULL || timer_status_cb == NULL){ return NULL; } coap_security_t *this = ns_dyn_mem_alloc(sizeof(coap_security_t)); if( !this ){ return NULL; } memset(this, 0, sizeof(coap_security_t)); if( -1 == coap_security_handler_init(this) ){ ns_dyn_mem_free(this); return NULL; } this->_remote_port = port; memcpy(this->_remote_address, address_ptr, 16); this->_conn_mode = mode; memset(this->_pw, 0, 64); this->_pw_len = 0; this->_socket_id = socket_id; this->_timer_id = timer_id; this->_send_cb = send_cb; this->_receive_cb = receive_cb; this->_start_timer_cb = start_timer_cb; this->_timer_status_cb = timer_status_cb; return this; }