KNX IoT
KNX IoT Point API stack implementation
oc_blockwise.h
Go to the documentation of this file.
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
20 #ifndef OC_BLOCKWISE_H
21 #define OC_BLOCKWISE_H
22 
23 #include "messaging/coap/coap.h"
24 #include "messaging/coap/transactions.h"
25 #include "oc_helpers.h"
26 #include "oc_ri.h"
27 #include "port/oc_connectivity.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
37 typedef enum {
41 
42 typedef struct oc_blockwise_state_s
43 {
44  struct oc_blockwise_state_s *next;
45  oc_string_t href;
46  oc_endpoint_t endpoint;
47  oc_method_t method;
48  oc_blockwise_role_t role;
49  uint32_t payload_size;
50  uint32_t next_block_offset;
51  uint8_t ref_count;
53 #ifdef OC_DYNAMIC_ALLOCATION
54 #ifdef OC_APP_DATA_BUFFER_POOL
55  void *block;
56 #endif /* OC_APP_DATA_BUFFER_POOL */
57  uint8_t *buffer;
58 #else /* OC_DYNAMIC_ALLOCATION */
59  uint8_t buffer[OC_MAX_APP_DATA_SIZE];
60 #endif /* !OC_DYNAMIC_ALLOCATION */
61  oc_string_t uri_query;
62  oc_content_format_t return_content_type;
63 #ifdef OC_CLIENT
64  uint8_t token[COAP_TOKEN_LEN];
65  uint8_t token_len;
66  uint16_t mid;
67  void *client_cb;
68 #endif /* OC_CLIENT */
69 } oc_blockwise_state_t;
70 
76 {
77  oc_blockwise_state_t base;
79 
85 {
86  oc_blockwise_state_t base;
87  uint8_t etag[COAP_ETAG_LEN];
89 #ifdef OC_CLIENT
90  int32_t observe_seq;
91 #endif /* OC_CLIENT */
93 
100 oc_blockwise_state_t *oc_blockwise_find_request_buffer_by_mid(uint16_t mid);
101 
108 oc_blockwise_state_t *oc_blockwise_find_response_buffer_by_mid(uint16_t mid);
109 
118  uint8_t *token, uint8_t token_len);
119 
128  uint8_t *token, uint8_t token_len);
129 
138  oc_endpoint_t *endpoint, void *client_cb);
139 
148  oc_endpoint_t *endpoint, void *client_cb);
149 
162 oc_blockwise_state_t *oc_blockwise_find_request_buffer(
163  const char *href, size_t href_len, oc_endpoint_t *endpoint,
164  oc_method_t method, const char *query, size_t query_len,
165  oc_blockwise_role_t role);
166 
179 oc_blockwise_state_t *oc_blockwise_find_response_buffer(
180  const char *href, size_t href_len, oc_endpoint_t *endpoint,
181  oc_method_t method, const char *query, size_t query_len,
182  oc_blockwise_role_t role);
183 
194 oc_blockwise_state_t *oc_blockwise_alloc_request_buffer(
195  const char *href, size_t href_len, oc_endpoint_t *endpoint,
196  oc_method_t method, oc_blockwise_role_t role);
197 
209  const char *href, size_t href_len, oc_endpoint_t *endpoint,
210  oc_method_t method, oc_blockwise_role_t role);
211 
217 void oc_blockwise_free_request_buffer(oc_blockwise_state_t *buffer);
218 
224 void oc_blockwise_free_response_buffer(oc_blockwise_state_t *buffer);
225 
235 const void *oc_blockwise_dispatch_block(oc_blockwise_state_t *buffer,
236  uint32_t block_offset,
237  uint32_t requested_block_size,
238  uint32_t *payload_size);
239 
250 bool oc_blockwise_handle_block(oc_blockwise_state_t *buffer,
251  uint32_t incoming_block_offset,
252  const uint8_t *incoming_block,
253  uint32_t incoming_block_size);
254 
261 
268 
276 oc_blockwise_state_t *oc_get_request_buffer_with_ptr(uint8_t *data);
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif /* OC_BLOCKWISE_H */
struct oc_blockwise_response_state_s oc_blockwise_response_state_t
the blockwise response state
oc_blockwise_state_t * oc_get_request_buffer_with_ptr(uint8_t *data)
get blockwise buffer that contains data in its payload
oc_blockwise_state_t * oc_blockwise_find_response_buffer_by_client_cb(oc_endpoint_t *endpoint, void *client_cb)
find the response by client callback & endpoint
void oc_blockwise_free_request_buffer(oc_blockwise_state_t *buffer)
free the request buffer
oc_blockwise_state_t * oc_blockwise_find_request_buffer_by_client_cb(oc_endpoint_t *endpoint, void *client_cb)
find the request by client callback & endpoint
oc_blockwise_role_t
role of the transfer
Definition: oc_blockwise.h:37
@ OC_BLOCKWISE_SERVER
server
Definition: oc_blockwise.h:39
@ OC_BLOCKWISE_CLIENT
client
Definition: oc_blockwise.h:38
oc_blockwise_state_t * oc_blockwise_alloc_response_buffer(const char *href, size_t href_len, oc_endpoint_t *endpoint, oc_method_t method, oc_blockwise_role_t role)
allocate the response buffer
oc_blockwise_state_t * oc_blockwise_alloc_request_buffer(const char *href, size_t href_len, oc_endpoint_t *endpoint, oc_method_t method, oc_blockwise_role_t role)
allocate the request buffer
bool oc_blockwise_handle_block(oc_blockwise_state_t *buffer, uint32_t incoming_block_offset, const uint8_t *incoming_block, uint32_t incoming_block_size)
handle the incoming block (partial message)
oc_blockwise_state_t * oc_blockwise_find_request_buffer(const char *href, size_t href_len, oc_endpoint_t *endpoint, oc_method_t method, const char *query, size_t query_len, oc_blockwise_role_t role)
find request buffer based on more information
oc_blockwise_state_t * oc_blockwise_find_response_buffer(const char *href, size_t href_len, oc_endpoint_t *endpoint, oc_method_t method, const char *query, size_t query_len, oc_blockwise_role_t role)
find response buffer based on more information
struct oc_blockwise_request_state_s oc_blockwise_request_state_t
the blockwise request state
void oc_blockwise_free_response_buffer(oc_blockwise_state_t *buffer)
free the response buffer
oc_blockwise_state_t * oc_blockwise_find_request_buffer_by_mid(uint16_t mid)
find the block wise request based on mid
oc_blockwise_state_t * oc_blockwise_find_response_buffer_by_token(uint8_t *token, uint8_t token_len)
find the response by token
const void * oc_blockwise_dispatch_block(oc_blockwise_state_t *buffer, uint32_t block_offset, uint32_t requested_block_size, uint32_t *payload_size)
send the block
oc_blockwise_state_t * oc_blockwise_find_request_buffer_by_token(uint8_t *token, uint8_t token_len)
find the request by token
void oc_blockwise_scrub_buffers(bool all)
free all blocks that are handled (ref_count = 0)
oc_blockwise_state_t * oc_blockwise_find_response_buffer_by_mid(uint16_t mid)
find the block wise response based on mid
void oc_blockwise_scrub_buffers_for_client_cb(void *cb)
scrub blocks for client side
platform abstraction of networking
generic helpers
resource internals
oc_method_t
CoAP methods.
Definition: oc_ri.h:124
oc_content_format_t
payload content formats
Definition: oc_ri.h:184
the blockwise request state
Definition: oc_blockwise.h:76
oc_blockwise_state_t base
blockwise state data
Definition: oc_blockwise.h:77
the blockwise response state
Definition: oc_blockwise.h:85
int32_t observe_seq
the observe sequence number
Definition: oc_blockwise.h:90
oc_blockwise_state_t base
blockwise state data
Definition: oc_blockwise.h:86
uint8_t etag[COAP_ETAG_LEN]
etag for the response
Definition: oc_blockwise.h:87
the endpoint information
Definition: oc_endpoint.h:78