mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-31 00:32:52 +00:00
goep_client + obex_message-builder: add functions for the length header
This commit is contained in:
parent
66a7447d6c
commit
49df53af84
@ -580,6 +580,15 @@ void goep_client_body_add_static(uint16_t goep_cid, const uint8_t * data, uint32
|
||||
obex_message_builder_body_add_static(buffer, buffer_len, data, length);
|
||||
}
|
||||
|
||||
void goep_client_body_fillup_static(uint16_t goep_cid, const uint8_t * data, uint32_t length, uint32_t * ret_length){
|
||||
UNUSED(goep_cid);
|
||||
goep_client_t * context = goep_client;
|
||||
|
||||
uint8_t * buffer = goep_client_get_outgoing_buffer(context);
|
||||
uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context);
|
||||
obex_message_builder_body_fillup_static(buffer, buffer_len, data, length, ret_length);
|
||||
}
|
||||
|
||||
void goep_client_header_add_name(uint16_t goep_cid, const char * name){
|
||||
UNUSED(goep_cid);
|
||||
goep_client_t * context = goep_client;
|
||||
@ -607,6 +616,15 @@ void goep_client_header_add_type(uint16_t goep_cid, const char * type){
|
||||
obex_message_builder_header_add_type(buffer, buffer_len, type);
|
||||
}
|
||||
|
||||
void goep_client_header_add_length(uint16_t goep_cid, uint32_t length){
|
||||
UNUSED(goep_cid);
|
||||
goep_client_t * context = goep_client;
|
||||
|
||||
uint8_t * buffer = goep_client_get_outgoing_buffer(context);
|
||||
uint16_t buffer_len = goep_client_get_outgoing_buffer_len(context);
|
||||
obex_message_builder_header_add_length(buffer, buffer_len, length);
|
||||
}
|
||||
|
||||
uint16_t goep_client_request_get_max_body_size(uint16_t goep_cid){
|
||||
UNUSED(goep_cid);
|
||||
goep_client_t * context = goep_client;
|
||||
|
@ -229,6 +229,13 @@ void goep_client_header_add_type(uint16_t goep_cid, const char * type);
|
||||
*/
|
||||
void goep_client_header_add_count(uint16_t goep_cid, uint32_t count);
|
||||
|
||||
/**
|
||||
* @brief Add length header to current request
|
||||
* @param goep_cid
|
||||
* @param length
|
||||
*/
|
||||
void goep_client_header_add_length(uint16_t goep_cid, uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Add application parameters header to current request
|
||||
* @param goep_cid
|
||||
@ -253,6 +260,15 @@ void goep_client_header_add_challenge_response(uint16_t goep_cid, const uint8_t
|
||||
*/
|
||||
void goep_client_body_add_static(uint16_t goep_cid, const uint8_t * data, uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Add body
|
||||
* @param goep_cid
|
||||
* @param data
|
||||
* @param length
|
||||
* @param ret_length
|
||||
*/
|
||||
void goep_client_body_fillup_static(uint16_t goep_cid, const uint8_t * data, uint32_t length, uint32_t * ret_length);
|
||||
|
||||
/**
|
||||
* @brief Execute prepared request
|
||||
* @param goep_cid
|
||||
|
@ -92,6 +92,22 @@ uint8_t obex_message_builder_header_add_variable(uint8_t * buffer, uint16_t buff
|
||||
return obex_message_builder_packet_append(buffer, buffer_len, header_data, header_data_length);
|
||||
}
|
||||
|
||||
uint8_t obex_message_builder_header_fillup_variable(uint8_t * buffer, uint16_t buffer_len, uint8_t header_type, const uint8_t * header_data, uint16_t header_data_length, uint32_t * ret_length){
|
||||
uint8_t header[3];
|
||||
header[0] = header_type;
|
||||
|
||||
if (sizeof (header) + header_data_length > buffer_len)
|
||||
header_data_length = buffer_len - sizeof (header);
|
||||
|
||||
big_endian_store_16(header, 1, sizeof(header) + header_data_length);
|
||||
*ret_length = 0;
|
||||
uint8_t status = obex_message_builder_packet_append(buffer, buffer_len, &header[0], sizeof(header));
|
||||
if (status != ERROR_CODE_SUCCESS) return status;
|
||||
|
||||
*ret_length = header_data_length;
|
||||
return obex_message_builder_packet_append(buffer, buffer_len, header_data, header_data_length);
|
||||
}
|
||||
|
||||
static uint8_t obex_message_builder_header_add_connection_id(uint8_t * buffer, uint16_t buffer_len, uint32_t obex_connection_id){
|
||||
// add connection_id header if set, must be first header if used
|
||||
if (obex_connection_id == OBEX_CONNECTION_ID_INVALID) return ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE;
|
||||
@ -171,6 +187,20 @@ uint8_t obex_message_builder_request_create_disconnect(uint8_t * buffer, uint16_
|
||||
return obex_message_builder_header_add_connection_id(buffer, buffer_len, obex_connection_id);
|
||||
}
|
||||
|
||||
uint8_t obex_message_builder_set_final_bit (uint8_t * buffer, uint16_t buffer_len, bool final){
|
||||
if (buffer_len < 1) return ERROR_CODE_MEMORY_CAPACITY_EXCEEDED;
|
||||
if (buffer[0] == OBEX_OPCODE_CONNECT ||
|
||||
buffer[0] == OBEX_OPCODE_DISCONNECT ||
|
||||
buffer[0] == OBEX_OPCODE_SETPATH ||
|
||||
buffer[0] == OBEX_OPCODE_SESSION ||
|
||||
buffer[0] == OBEX_OPCODE_ABORT){
|
||||
return ERROR_CODE_COMMAND_DISALLOWED;
|
||||
}
|
||||
buffer[0] &= ~OBEX_OPCODE_FINAL_BIT_MASK;
|
||||
buffer[0] |= (final ? OBEX_OPCODE_FINAL_BIT_MASK : 0);
|
||||
return ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t obex_message_builder_header_add_srm_enable(uint8_t * buffer, uint16_t buffer_len){
|
||||
return obex_message_builder_header_add_byte(buffer, buffer_len, OBEX_HEADER_SINGLE_RESPONSE_MODE, OBEX_SRM_ENABLE);
|
||||
}
|
||||
@ -195,6 +225,10 @@ uint8_t obex_message_builder_body_add_static(uint8_t * buffer, uint16_t buffer_l
|
||||
return obex_message_builder_header_add_variable(buffer, buffer_len, OBEX_HEADER_END_OF_BODY, data, length);
|
||||
}
|
||||
|
||||
uint8_t obex_message_builder_body_fillup_static(uint8_t * buffer, uint16_t buffer_len, const uint8_t * data, uint32_t length, uint32_t *ret_length){
|
||||
return obex_message_builder_header_fillup_variable(buffer, buffer_len, OBEX_HEADER_END_OF_BODY, data, length, ret_length);
|
||||
}
|
||||
|
||||
uint8_t obex_message_builder_header_add_name_prefix(uint8_t * buffer, uint16_t buffer_len, const char * name, uint16_t name_len){
|
||||
// non-empty string have trailing \0
|
||||
bool add_trailing_zero = name_len > 0;
|
||||
@ -234,3 +268,7 @@ uint8_t obex_message_builder_header_add_type(uint8_t * buffer, uint16_t buffer_l
|
||||
if (status != ERROR_CODE_SUCCESS) return status;
|
||||
return obex_message_builder_packet_append(buffer, buffer_len, (const uint8_t*)type, len_incl_zero);
|
||||
}
|
||||
|
||||
uint8_t obex_message_builder_header_add_length(uint8_t * buffer, uint16_t buffer_len, uint32_t length){
|
||||
return obex_message_builder_header_add_word(buffer, buffer_len, OBEX_HEADER_LENGTH, length);
|
||||
}
|
||||
|
@ -154,6 +154,15 @@ uint8_t obex_message_builder_request_create_abort(uint8_t * buffer, uint16_t buf
|
||||
*/
|
||||
uint8_t obex_message_builder_request_create_set_path(uint8_t * buffer, uint16_t buffer_len, uint8_t flags, uint32_t connection_id);
|
||||
|
||||
/**
|
||||
* @brief Control the "final" bit
|
||||
* @param buffer
|
||||
* @param buffer_len
|
||||
* @param final
|
||||
* @return status
|
||||
*/
|
||||
uint8_t obex_message_builder_set_final_bit (uint8_t * buffer, uint16_t buffer_len, bool final);
|
||||
|
||||
/**
|
||||
* @brief Add SRM Enable
|
||||
* @param buffer
|
||||
@ -193,6 +202,18 @@ uint8_t obex_message_builder_header_add_word(uint8_t * buffer, uint16_t buffer_l
|
||||
*/
|
||||
uint8_t obex_message_builder_header_add_variable(uint8_t * buffer, uint16_t buffer_len, uint8_t header_type, const uint8_t * header_data, uint16_t header_data_length);
|
||||
|
||||
/**
|
||||
* @brief Add (partial) header with variable size
|
||||
* @param buffer
|
||||
* @param buffer_len
|
||||
* @param header_type
|
||||
* @param header_data
|
||||
* @param header_data_length
|
||||
* @param ret_length
|
||||
* @return status
|
||||
*/
|
||||
uint8_t obex_message_builder_header_fillup_variable(uint8_t * buffer, uint16_t buffer_len, uint8_t header_type, const uint8_t * header_data, uint16_t header_data_length, uint32_t * ret_length);
|
||||
|
||||
/**
|
||||
* @brief Add name header to current request
|
||||
* @param buffer
|
||||
@ -250,6 +271,15 @@ uint8_t obex_message_builder_header_add_type(uint8_t * buffer, uint16_t buffer_l
|
||||
*/
|
||||
uint8_t obex_message_builder_header_add_count(uint8_t * buffer, uint16_t buffer_len, uint32_t count);
|
||||
|
||||
/**
|
||||
* @brief Add length header to current request
|
||||
* @param buffer
|
||||
* @param buffer_len
|
||||
* @param lenght
|
||||
* @return status
|
||||
*/
|
||||
uint8_t obex_message_builder_header_add_length(uint8_t * buffer, uint16_t buffer_len, uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Add application parameters header to current request
|
||||
* @param buffer
|
||||
@ -280,6 +310,17 @@ uint8_t obex_message_builder_header_add_challenge_response(uint8_t * buffer, uin
|
||||
*/
|
||||
uint8_t obex_message_builder_body_add_static(uint8_t * buffer, uint16_t buffer_len, const uint8_t * data, uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Add body
|
||||
* @param buffer
|
||||
* @param buffer_len
|
||||
* @param data
|
||||
* @param length
|
||||
* @param ret_length
|
||||
* @return status
|
||||
*/
|
||||
uint8_t obex_message_builder_body_fillup_static(uint8_t * buffer, uint16_t buffer_len, const uint8_t * data, uint32_t length, uint32_t *ret_length);
|
||||
|
||||
/* API_END */
|
||||
|
||||
// int obex_message_builder_body_add_dynamic(uint8_t * buffer, uint16_t buffer_len, uint32_t length, void (*data_callback)(uint32_t offset, uint8_t * buffer, uint32_t len));
|
||||
|
Loading…
x
Reference in New Issue
Block a user