Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include "osi/osi.h"
#include "osi/allocator.h"
#include "common/bt_target.h"
#include "stack/obex_api.h"
#include "stack/goep_common.h"
#include "stack/goepc_api.h"
#include "goep_int.h"
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/bt/host/bluedroid/stack/goep/goepc_api.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include "osi/osi.h" #include "osi/allocator.h" #include "common/bt_target.h" #include "stack/obex_api.h" #include "stack/goep_common.h" #include "stack/goepc_api.h" #include "goep_int.h"8 includes #if (GOEPC_INCLUDED == TRUE) /******************************************************************************* ** ** Function GOEPC_Init ** ** Description Initialize GOEP Client role, must call before using any ** other GOEPC APIs ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_Init(void) { #if (GOEP_DYNAMIC_MEMORY) if (!goepc_cb_ptr) { goepc_cb_ptr = (tGOEPC_CB *)osi_malloc(sizeof(tGOEPC_CB)); if (!goepc_cb_ptr) { return GOEP_NO_RESOURCES; }{...} }{...} /* ... */#endif /* #if (GOEP_DYNAMIC_MEMORY) */ memset(&goepc_cb, 0, sizeof(tGOEPC_CB)); goepc_cb.trace_level = BT_TRACE_LEVEL_ERROR; return GOEP_SUCCESS; }{...} /******************************************************************************* ** ** Function GOEPC_Deinit ** ** Description Deinit GOEP Client role, once deinit, can not use any other ** GOEPC APIs until call GOEPC_Init again ** *******************************************************************************//* ... */ void GOEPC_Deinit(void) { #if (GOEP_DYNAMIC_MEMORY) if (goepc_cb_ptr) { osi_free(goepc_cb_ptr); goepc_cb_ptr = NULL; }{...} /* ... */#endif /* #if (GOEP_DYNAMIC_MEMORY) */ }{...} /******************************************************************************* ** ** Function GOEPC_Open ** ** Description Start the progress to establish a GOEP connection to server ** ** Returns GOEP_SUCCESS if successful, otherwise failed, when the ** connection is established, GOEPC_OPENED_EVT will come ** *******************************************************************************//* ... */ UINT16 GOEPC_Open(tOBEX_SVR_INFO *svr, tGOEPC_EVT_CBACK callback, UINT16 *out_handle) { UINT16 ret = GOEP_SUCCESS; tGOEPC_CCB *p_ccb = NULL; do { /* check parameter, allow out_handle to be NULL */ if (svr == NULL || callback == NULL) { ret = GOEP_INVALID_PARAM; break; }{...} p_ccb = goepc_allocate_ccb(); if (p_ccb == NULL) { ret = GOEP_NO_RESOURCES; break; }{...} if (OBEX_CreateConn(svr, goepc_obex_callback, &p_ccb->obex_handle) != OBEX_SUCCESS) { ret = GOEP_TL_ERROR; break; }{...} /* success */ p_ccb->callback = callback; p_ccb->state = GOEPC_STATE_OPENING; if (out_handle) { *out_handle = p_ccb->allocated; }{...} }{...} while (0); if (ret != GOEP_SUCCESS && p_ccb != NULL) { goepc_free_ccb(p_ccb); }{...} return ret; }{...} /******************************************************************************* ** ** Function GOEPC_Close ** ** Description Close a GOEP connection immediately ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_Close(UINT16 handle) { tGOEPC_CCB *p_ccb = NULL; UINT16 ccb_idx = handle - 1; if (ccb_idx >= GOEPC_MAX_CONNECTION || !goepc_cb.ccb[ccb_idx].allocated) { return GOEP_BAD_HANDLE; }{...} p_ccb = &goepc_cb.ccb[ccb_idx]; if (p_ccb->obex_handle) { OBEX_RemoveConn(p_ccb->obex_handle); }{...} goepc_free_ccb(p_ccb); return GOEP_SUCCESS; }{...} /******************************************************************************* ** ** Function GOEPC_SendRequest ** ** Description Send the prepared request packet to server ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_SendRequest(UINT16 handle) { UINT16 ret = GOEP_SUCCESS; tGOEPC_CCB *p_ccb = NULL; BOOLEAN final = FALSE; do { UINT16 ccb_idx = handle - 1; if (ccb_idx >= GOEPC_MAX_CONNECTION || !goepc_cb.ccb[ccb_idx].allocated) { ret = GOEP_BAD_HANDLE; break; }{...} p_ccb = &goepc_cb.ccb[ccb_idx]; if (p_ccb->pkt == NULL) { ret = GOEP_INVALID_STATE; break; }{...} final = OBEX_CheckFinalBit(p_ccb->pkt); /* check whether state machine allow this operation */ if (!goepc_check_obex_req_allow(p_ccb->state, final)) { ret = GOEP_INVALID_STATE; break; }{...} if (p_ccb->congest) { ret = GOEP_CONGEST; break; }{...} /* execute srm state machine */ goepc_srm_sm_execute(p_ccb, TRUE, p_ccb->pkt_srm_en, p_ccb->pkt_srm_wait); tGOEPC_DATA data; data.pkt = p_ccb->pkt; p_ccb->last_pkt_opcode = p_ccb->curr_pkt_opcode; p_ccb->pkt = NULL; p_ccb->pkt_srm_en = FALSE; p_ccb->pkt_srm_wait = FALSE; /* execute main state machine */ if (final) { goepc_sm_execute(p_ccb, GOEPC_SM_EVENT_REQ_FB, &data); }{...} else { goepc_sm_execute(p_ccb, GOEPC_SM_EVENT_REQ, &data); }{...} /* since goepc_sm_execute may free ccb, can not access ccb here */ }{...} while (0); return ret; }{...} /******************************************************************************* ** ** Function GOEPC_PrepareRequest ** ** Description Prepare a request packet, packet will be store internally ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_PrepareRequest(UINT16 handle, tOBEX_PARSE_INFO *info, UINT16 buff_size) { UINT16 ret = GOEP_SUCCESS; tGOEPC_CCB *p_ccb = NULL; BT_HDR *pkt = NULL; do { UINT16 ccb_idx = handle - 1; if (ccb_idx >= GOEPC_MAX_CONNECTION || !goepc_cb.ccb[ccb_idx].allocated) { ret = GOEP_BAD_HANDLE; break; }{...} p_ccb = &goepc_cb.ccb[ccb_idx]; if (info == NULL || buff_size < OBEX_MIN_PACKET_SIZE) { ret = GOEP_INVALID_PARAM; break; }{...} if (p_ccb->pkt != NULL) { ret = GOEP_INVALID_STATE; break; }{...} if (!goepc_check_obex_req_param(info)) { ret = GOEP_INVALID_PARAM; break; }{...} if (OBEX_BuildRequest(info, buff_size, &pkt) != OBEX_SUCCESS) { ret = GOEP_NO_RESOURCES; break; }{...} p_ccb->curr_pkt_opcode = info->opcode; p_ccb->pkt = pkt; }{...} while (0); return ret; }{...} /******************************************************************************* ** ** Function GOEPC_DropRequest ** ** Description Drop the prepared internal request packet ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_DropRequest(UINT16 handle) { UINT16 ccb_idx = handle - 1; if (ccb_idx >= GOEPC_MAX_CONNECTION || !goepc_cb.ccb[ccb_idx].allocated) { return GOEP_BAD_HANDLE; }{...} tGOEPC_CCB *p_ccb = &goepc_cb.ccb[ccb_idx]; if (p_ccb->pkt == NULL) { return GOEP_INVALID_STATE; }{...} osi_free(p_ccb->pkt); p_ccb->pkt = NULL; p_ccb->pkt_srm_en = FALSE; p_ccb->pkt_srm_wait = FALSE; return GOEP_SUCCESS; }{...} /******************************************************************************* ** ** Function GOEPC_RequestSetSRM ** ** Description Modify the prepared internal request packet, append SRM header ** or SRMP header ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_RequestSetSRM(UINT16 handle, BOOLEAN srm_en, BOOLEAN srm_wait) { UINT16 ret = GOEP_SUCCESS; tGOEPC_CCB *p_ccb = NULL; do { UINT16 ccb_idx = handle - 1; if (ccb_idx >= GOEPC_MAX_CONNECTION || !goepc_cb.ccb[ccb_idx].allocated) { ret = GOEP_BAD_HANDLE; break; }{...} p_ccb = &goepc_cb.ccb[ccb_idx]; if (!srm_en && !srm_wait) { ret = GOEP_INVALID_PARAM; break; }{...} if (p_ccb->pkt == NULL) { ret = GOEP_INVALID_STATE; break; }{...} if (srm_en) { if (OBEX_AppendHeaderSRM(p_ccb->pkt, OBEX_SRM_ENABLE) == OBEX_SUCCESS) { p_ccb->pkt_srm_en = TRUE; }{...} else { ret = GOEP_NO_RESOURCES; break; }{...} }{...} if (srm_wait) { if (OBEX_AppendHeaderSRMP(p_ccb->pkt, OBEX_SRMP_WAIT) == OBEX_SUCCESS) { p_ccb->pkt_srm_wait = TRUE; }{...} else { ret = GOEP_NO_RESOURCES; break; }{...} }{...} }{...} while (0); return ret; }{...} /******************************************************************************* ** ** Function GOEPC_RequestAddHeader ** ** Description Modify the prepared internal request packet, append header ** ** Returns GOEP_SUCCESS if successful, otherwise failed ** *******************************************************************************//* ... */ UINT16 GOEPC_RequestAddHeader(UINT16 handle, UINT8 header_id, const UINT8 *data, UINT16 data_len) { UINT16 ret = GOEP_SUCCESS; tGOEPC_CCB *p_ccb = NULL; do { UINT16 ccb_idx = handle - 1; if (ccb_idx >= GOEPC_MAX_CONNECTION || !goepc_cb.ccb[ccb_idx].allocated) { ret = GOEP_BAD_HANDLE; break; }{...} p_ccb = &goepc_cb.ccb[ccb_idx]; if (p_ccb->pkt == NULL) { ret = GOEP_INVALID_STATE; break; }{...} if ((data == NULL && data_len != 0) || (data != NULL && data_len == 0)) { ret = GOEP_INVALID_PARAM; break; }{...} if (OBEX_AppendHeaderRaw(p_ccb->pkt, header_id, data, data_len) != OBEX_SUCCESS) { ret = GOEP_NO_RESOURCES; break; }{...} }{...} while (0); return ret; }{...} /* ... */ #endif /* #if (GOEPC_INCLUDED == TRUE) */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.