-
Notifications
You must be signed in to change notification settings - Fork 28
/
mible_api.c
954 lines (872 loc) · 32.8 KB
/
mible_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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
// Copyright [2017] [Beijing Xiaomi Mobile Software Co., Ltd]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mible_api.h"
#include "mible_port.h"
#include "mible_type.h"
#ifndef MIBLE_MAX_USERS
#define MIBLE_MAX_USERS 4
#endif
/* GAP, GATTS, GATTC event callback function */
static uint8_t m_gap_users, m_gattc_users, m_gatts_users, m_arch_users;
static mible_gap_callback_t m_gap_cb_table[MIBLE_MAX_USERS];
static mible_gatts_callback_t m_gatts_cb_table[MIBLE_MAX_USERS];
static mible_gattc_callback_t m_gattc_cb_table[MIBLE_MAX_USERS];
static mible_arch_callback_t m_arch_cb_table[MIBLE_MAX_USERS];
int mible_gap_register(mible_gap_callback_t cb)
{
int ret;
CRITICAL_SECTION_ENTER();
if (m_gap_users == MIBLE_MAX_USERS) {
ret = MI_ERR_RESOURCES;
} else {
m_gap_cb_table[m_gap_users] = cb;
m_gap_users++;
ret = MI_SUCCESS;
}
CRITICAL_SECTION_EXIT();
return ret;
}
int mible_gattc_register(mible_gattc_callback_t cb)
{
int ret;
CRITICAL_SECTION_ENTER();
if (m_gattc_users == MIBLE_MAX_USERS) {
ret = MI_ERR_RESOURCES;
} else {
m_gattc_cb_table[m_gattc_users] = cb;
m_gattc_users++;
ret = MI_SUCCESS;
}
CRITICAL_SECTION_EXIT();
return ret;
}
int mible_gatts_register(mible_gatts_callback_t cb)
{
int ret;
CRITICAL_SECTION_ENTER();
if (m_gatts_users == MIBLE_MAX_USERS) {
ret = MI_ERR_RESOURCES;
} else {
m_gatts_cb_table[m_gatts_users] = cb;
m_gatts_users++;
ret = MI_SUCCESS;
}
CRITICAL_SECTION_EXIT();
return ret;
}
int mible_arch_register(mible_arch_callback_t cb)
{
int ret;
CRITICAL_SECTION_ENTER();
if (m_arch_users == MIBLE_MAX_USERS) {
ret = MI_ERR_RESOURCES;
} else {
m_arch_cb_table[m_arch_users] = cb;
m_arch_users++;
ret = MI_SUCCESS;
}
CRITICAL_SECTION_EXIT();
return ret;
}
/**
*@brief This function is MIBLE GAP related event callback function.
*@param [in] evt : GAP EVENT
* [in] param : callback parameters corresponding to evt
*@return Void
*@note You should support this function in your own ble stack .
* Make sure when the corresponding event occurs, be able to call this
*function
* and pass in the corresponding parameters.
*/
void mible_gap_event_callback(mible_gap_evt_t evt, mible_gap_evt_param_t* param)
{
for (int user = 0; user < MIBLE_MAX_USERS; user++) {
if (m_gap_cb_table[user] != NULL) {
m_gap_cb_table[user](evt, param);
}
}
}
/**
*@brief This function is MIBLE GATTS related event callback function.
*@param [in] evt : GATTS EVENT
* [in] param : callback parameters corresponding to evt
*@return Void
*@note You should support this function in your own ble stack .
Make sure when the corresponding event occurs, be able to call this
function and pass in the corresponding parameters.
*/
void mible_gatts_event_callback(mible_gatts_evt_t evt,
mible_gatts_evt_param_t* param)
{
for (int user = 0; user < MIBLE_MAX_USERS; user++) {
if (m_gatts_cb_table[user] != NULL) {
m_gatts_cb_table[user](evt, param);
}
}
}
/**
*@brief This function is MIBLE GATTC related event callback function.
*@param [in] evt : GATTC EVENT
* [in] param : callback parameters corresponding to evt
*@return Void
*@note You should support this function in your own ble stack .
Make sure when the corresponding event occurs, be able to call this
function and pass in the corresponding parameters.
*/
void mible_gattc_event_callback(mible_gattc_evt_t evt,
mible_gattc_evt_param_t* param)
{
for (int user = 0; user < MIBLE_MAX_USERS; user++) {
if (m_gattc_cb_table[user] != NULL) {
m_gattc_cb_table[user](evt, param);
}
}
}
/*
*@brief This function is mible_arch api related event callback function.
*@param [in] evt: asynchronous function complete event
* [in] param: the return of asynchronous function
*@note You should support this function in corresponding asynchronous function.
* For now, mible_gatts_service_int and mible_record_write is asynchronous.
* */
void mible_arch_event_callback(mible_arch_event_t evt,
mible_arch_evt_param_t* param)
{
for (int user = 0; user < MIBLE_MAX_USERS; user++) {
if (m_arch_cb_table[user] != NULL) {
m_arch_cb_table[user](evt, param);
}
}
}
/**
* GAP APIs
*/
/**
* @brief Get BLE mac address.
* @param [out] mac: pointer to data
* @return MI_SUCCESS The requested mac address were written to mac
* MI_ERR_INTERNAL No mac address found.
* @note: You should copy gap mac to mac[6]
* */
__WEAK mible_status_t mible_gap_address_get(mible_addr_t mac)
{
return MI_SUCCESS;
}
/**
* @brief Start scanning
* @param [in] scan_type: passive or active scaning
* [in] scan_param: scan parameters including interval, windows
* and timeout
* @return MI_SUCCESS Successfully initiated scanning procedure.
* MI_ERR_INVALID_STATE Has initiated scanning procedure.
* MI_ERR_INVALID_PARAM Invalid parameter(s) supplied.
* MI_ERR_BUSY The stack is busy, process pending
* events and retry.
* @note Other default scanning parameters : public address, no
* whitelist.
* The scan response is given through
* MIBLE_GAP_EVT_ADV_REPORT event
*/
__WEAK mible_status_t mible_gap_scan_start(mible_gap_scan_type_t scan_type,
mible_gap_scan_param_t scan_param)
{
return MI_SUCCESS;
}
/**
* @brief Stop scanning
* @param void
* @return MI_SUCCESS Successfully stopped scanning procedure.
* MI_ERR_INVALID_STATE Not in scanning state.
* */
__WEAK mible_status_t mible_gap_scan_stop(void)
{
return MI_SUCCESS;
}
/**
* @brief Get scan param
* @param [out] scan_param: scan interval and window
* @return MI_SUCCESS Successfully stopped scanning procedure.
* MI_ERR_INVALID_STATE Not in scanning state.
* */
__WEAK mible_status_t mible_gap_scan_param_get(mible_gap_scan_param_t *scan_param)
{
return MI_SUCCESS;
}
/**
* @brief Start advertising
* @param [in] p_adv_param : pointer to advertising parameters, see
* mible_gap_adv_param_t for details
* @return MI_SUCCESS Successfully initiated advertising procedure.
* MI_ERR_INVALID_STATE Initiated connectable advertising procedure
* when connected.
* MI_ERR_INVALID_PARAM Invalid parameter(s) supplied.
* MI_ERR_BUSY The stack is busy, process pending events and
* retry.
* MI_ERR_RESOURCES Stop one or more currently active roles
* (Central, Peripheral or Observer) and try again.
* @note Other default advertising parameters: local public address , no
* filter policy
* */
__WEAK mible_status_t mible_gap_adv_start(mible_gap_adv_param_t *p_param)
{
return MI_SUCCESS;
}
/**
* @brief Config advertising data
* @param [in] p_data : Raw data to be placed in advertising packet. If NULL, no changes are made to the current advertising packet.
* @param [in] dlen : Data length for p_data. Max size: 31 octets. Should be 0 if p_data is NULL, can be 0 if p_data is not NULL.
* @param [in] p_sr_data : Raw data to be placed in scan response packet. If NULL, no changes are made to the current scan response packet data.
* @param [in] srdlen : Data length for p_sr_data. Max size: BLE_GAP_ADV_MAX_SIZE octets. Should be 0 if p_sr_data is NULL, can be 0 if p_data is not NULL.
* @return MI_SUCCESS Successfully set advertising data.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_PARAM Invalid parameter(s) supplied.
* */
__WEAK mible_status_t mible_gap_adv_data_set(uint8_t const * p_data,
uint8_t dlen, uint8_t const *p_sr_data, uint8_t srdlen)
{
return MI_SUCCESS;
}
/**
* @brief Stop advertising
* @param void
* @return MI_SUCCESS Successfully stopped advertising procedure.
* MI_ERR_INVALID_STATE Not in advertising state.
* */
__WEAK mible_status_t mible_gap_adv_stop(void)
{
return MI_SUCCESS;
}
/**
* @brief Create a Direct connection
* @param [in] scan_param : scanning parameters, see TYPE
* mible_gap_scan_param_t for details.
* [in] conn_param : connection parameters, see TYPE
* mible_gap_connect_t for details.
* @return MI_SUCCESS Successfully initiated connection procedure.
* MI_ERR_INVALID_STATE Initiated connection procedure in connected state.
* MI_ERR_INVALID_PARAM Invalid parameter(s) supplied.
* MI_ERR_BUSY The stack is busy, process pending events and retry.
* MI_ERR_RESOURCES Stop one or more currently active roles
* (Central, Peripheral or Observer) and try again
* MIBLE_ERR_GAP_INVALID_BLE_ADDR Invalid Bluetooth address
* supplied.
* @note Own and peer address are both public.
* The connection result is given by MIBLE_GAP_EVT_CONNECTED
* event
* */
__WEAK mible_status_t mible_gap_connect(mible_gap_scan_param_t scan_param,
mible_gap_connect_t conn_param)
{
return MI_SUCCESS;
}
/**
* @brief Disconnect from peer
* @param [in] conn_handle: the connection handle
* @return MI_SUCCESS Successfully disconnected.
* MI_ERR_INVALID_STATE Not in connnection.
* MIBLE_ERR_INVALID_CONN_HANDLE
* @note This function can be used by both central role and periphral
* role.
* */
__WEAK mible_status_t mible_gap_disconnect(uint16_t conn_handle)
{
return MI_SUCCESS;
}
/**
* @brief Update the connection parameters.
* @param [in] conn_handle: the connection handle.
* [in] conn_params: the connection parameters.
* @return MI_SUCCESS The Connection Update procedure has been
*started successfully.
* MI_ERR_INVALID_STATE Initiated this procedure in disconnected
*state.
* MI_ERR_INVALID_PARAM Invalid parameter(s) supplied.
* MI_ERR_BUSY The stack is busy, process pending events and
*retry.
* MIBLE_ERR_INVALID_CONN_HANDLE
* @note This function can be used by both central role and peripheral
*role.
* */
__WEAK mible_status_t mible_gap_update_conn_params(uint16_t conn_handle,
mible_gap_conn_param_t conn_params)
{
return MI_SUCCESS;
}
/**
* GATT Server APIs
*/
/**
* @brief Add a Service to a GATT server
* @param [in|out] p_server_db: pointer to mible service data type
* of mible_gatts_db_t, see TYPE mible_gatts_db_t for details.
* @return MI_SUCCESS Successfully added a service declaration.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_PARAM Invalid parameter(s) supplied.
* MI_ERR_NO_MEM Not enough memory to complete operation.
* @note This function can be implemented asynchronous. When service inition complete, call mible_arch_event_callback function and pass in MIBLE_ARCH_EVT_GATTS_SRV_INIT_CMP event and result.
* */
__WEAK mible_status_t mible_gatts_service_init(mible_gatts_db_t *p_server_db)
{
return MI_SUCCESS;
}
/**
* @brief Set characteristic value
* @param [in] srv_handle: service handle
* [in] value_handle: characteristic value handle
* [in] offset: the offset from which the attribute value has
*to be updated
* [in] p_value: pointer to data
* [in] len: data length
* @return MI_SUCCESS Successfully retrieved the value of the
*attribute.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_PARAM Invalid parameter (offset) supplied.
* MI_ERR_INVALID_LENGTH Invalid length supplied.
* MIBLE_ERR_ATT_INVALID_HANDLE Attribute not found.
* MIBLE_ERR_GATT_INVALID_ATT_TYPE Attributes are not modifiable by
*the application.
* */
__WEAK mible_status_t mible_gatts_value_set(uint16_t srv_handle,
uint16_t value_handle, uint8_t offset, uint8_t* p_value, uint8_t len)
{
return MI_SUCCESS;
}
/**
* @brief Get charicteristic value as a GATTS.
* @param [in] srv_handle: service handle
* [in] value_handle: characteristic value handle
* [out] p_value: pointer to data which stores characteristic value
* [out] p_len: pointer to data length.
* @return MI_SUCCESS Successfully get the value of the attribute.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_PARAM Invalid parameter (offset) supplied.
* MI_ERR_INVALID_LENGTH Invalid length supplied.
* MIBLE_ERR_ATT_INVALID_HANDLE Attribute not found.
**/
__WEAK mible_status_t mible_gatts_value_get(uint16_t srv_handle,
uint16_t value_handle, uint8_t* p_value, uint8_t *p_len)
{
return MI_SUCCESS;
}
/**
* @brief Set characteristic value and notify it to client.
* @param [in] conn_handle: conn handle
* [in] srv_handle: service handle
* [in] char_value_handle: characteristic value handle
* [in] offset: the offset from which the attribute value has to
* be updated
* [in] p_value: pointer to data
* [in] len: data length
* [in] type : notification = 1; indication = 2;
*
* @return MI_SUCCESS Successfully queued a notification or
* indication for transmission,
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_PARAM Invalid parameter (offset) supplied.
* MI_ERR_INVALID_STATE Invalid Connection State or notifications
* and/or indications not enabled in the CCCD.
* MI_ERR_INVALID_LENGTH Invalid length supplied.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_ATT_INVALID_HANDLE Attribute not found.
* MIBLE_ERR_GATT_INVALID_ATT_TYPE //Attributes are not modifiable by
* the application.
* @note This function checks for the relevant Client Characteristic
* Configuration descriptor value to verify that the relevant operation (notification or
* indication) has been enabled by the client.
* */
__WEAK mible_status_t mible_gatts_notify_or_indicate(uint16_t conn_handle,
uint16_t srv_handle, uint16_t char_value_handle, uint8_t offset,
uint8_t* p_value, uint8_t len, uint8_t type)
{
return MI_SUCCESS;
}
/**
* @brief Respond to a Read/Write user authorization request.
* @param [in] conn_handle: conn handle
* [in] status: 1: permit to change value ; 0: reject to change value
* [in] char_value_handle: characteristic handle
* [in] offset: the offset from which the attribute value has to
* be updated
* [in] p_value: Pointer to new value used to update the attribute value.
* [in] len: data length
* [in] type : read response = 1; write response = 2;
*
* @return MI_SUCCESS Successfully queued a response to the peer, and in the case of a write operation, GATT updated.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_PARAM Invalid parameter (offset) supplied.
* MI_ERR_INVALID_STATE Invalid Connection State or no authorization request pending.
* MI_ERR_INVALID_LENGTH Invalid length supplied.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_ATT_INVALID_HANDLE Attribute not found.
* @note This call should only be used as a response to a MIBLE_GATTS_EVT_READ/WRITE_PERMIT_REQ
* event issued to the application.
* */
__WEAK mible_status_t mible_gatts_rw_auth_reply(uint16_t conn_handle,
uint8_t status, uint16_t char_value_handle, uint8_t offset,
uint8_t* p_value, uint8_t len, uint8_t type)
{
return MI_SUCCESS;
}
/**
* GATT Client APIs
*/
/**
* @brief Discover primary service by service UUID.
* @param [in] conn_handle: connect handle
* [in] handle_range: search range for primary sevice
*discovery procedure
* [in] p_srv_uuid: pointer to service uuid
* @return MI_SUCCESS Successfully started or resumed the Primary
*Service Discovery procedure.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_STATE Invalid Connection State.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_INVALID_CONN_HANDLE Invaild connection handle.
* @note The response is given through
*MIBLE_GATTC_EVT_PRIMARY_SERVICE_DISCOVER_RESP event
* */
__WEAK mible_status_t mible_gattc_primary_service_discover_by_uuid(
uint16_t conn_handle, mible_handle_range_t handle_range,
mible_uuid_t* p_srv_uuid)
{
return MI_SUCCESS;
}
/**
* @brief Discover characteristic by characteristic UUID.
* @param [in] conn_handle: connect handle
* [in] handle_range: search range for characteristic discovery
* procedure
* [in] p_char_uuid: pointer to characteristic uuid
* @return MI_SUCCESS Successfully started or resumed the
* Characteristic Discovery procedure.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_STATE Invalid Connection State.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_INVALID_CONN_HANDLE Invaild connection handle.
* @note The response is given through
* MIBLE_GATTC_CHR_DISCOVER_BY_UUID_RESP event
* */
__WEAK mible_status_t mible_gattc_char_discover_by_uuid(uint16_t conn_handle,
mible_handle_range_t handle_range, mible_uuid_t* p_char_uuid)
{
return MI_SUCCESS;
}
/**
* @brief Discover characteristic client configuration descriptor
* @param [in] conn_handle: connection handle
* [in] handle_range: search range
* @return MI_SUCCESS Successfully started Clien Config Descriptor
* Discovery procedure.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_STATE Invalid Connection State.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_INVALID_CONN_HANDLE Invaild connection handle.
* @note Maybe run the charicteristic descriptor discover procedure firstly,
* then pick up the client configuration descriptor which att type is 0x2092
* The response is given through MIBLE_GATTC_CCCD_DISCOVER_RESP
* event
* Only return the first cccd handle within the specified
* range.
* */
__WEAK mible_status_t mible_gattc_clt_cfg_descriptor_discover(
uint16_t conn_handle, mible_handle_range_t handle_range)
{
return MI_SUCCESS;
}
/**
* @brief Read characteristic value by UUID
* @param [in] conn_handle: connnection handle
* [in] handle_range: search range
* [in] p_char_uuid: pointer to characteristic uuid
* @return MI_SUCCESS Successfully started or resumed the Read
* using Characteristic UUID procedure.
* MI_ERR_INVALID_STATE Invalid Connection State.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_INVALID_CONN_HANDLE Invaild connection handle.
* @note The response is given through
* MIBLE_GATTC_EVT_READ_CHR_VALUE_BY_UUID_RESP event
* */
__WEAK mible_status_t mible_gattc_read_char_value_by_uuid(uint16_t conn_handle,
mible_handle_range_t handle_range, mible_uuid_t *p_char_uuid)
{
return MI_SUCCESS;
}
/**
* @brief Write value by handle with response
* @param [in] conn_handle: connection handle
* [in] handle: handle to the attribute to be written.
* [in] p_value: pointer to data
* [in] len: data length
* @return MI_SUCCESS Successfully started the Write with response
* procedure.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_STATE Invalid Connection State.
* MI_ERR_INVALID_LENGTH Invalid length supplied.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_INVALID_CONN_HANDLE Invaild connection handle.
* @note The response is given through MIBLE_GATTC_EVT_WRITE_RESP event
*
* */
__WEAK mible_status_t mible_gattc_write_with_rsp(uint16_t conn_handle,
uint16_t att_handle, uint8_t* p_value, uint8_t len)
{
return MI_SUCCESS;
}
/**
* @brief Write value by handle without response
* @param [in] conn_handle: connection handle
* [in] att_handle: handle to the attribute to be written.
* [in] p_value: pointer to data
* [in] len: data length
* @return MI_SUCCESS Successfully started the Write Cmd procedure.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_STATE Invalid Connection State.
* MI_ERR_INVALID_LENGTH Invalid length supplied.
* MI_ERR_BUSY Procedure already in progress.
* MIBLE_ERR_INVALID_CONN_HANDLE Invaild connection handle.
* @note no response
* */
__WEAK mible_status_t mible_gattc_write_cmd(uint16_t conn_handle,
uint16_t att_handle, uint8_t* p_value, uint8_t len)
{
return MI_SUCCESS;
}
/**
* SOFT TIMER APIs
*/
/**
* @brief Create a timer.
* @param [out] p_timer_id: a pointer to timer id address which can uniquely identify the timer.
* [in] timeout_handler: a pointer to a function which can be
* called when the timer expires.
* [in] mode: repeated or single shot.
* @return MI_SUCCESS If the timer was successfully created.
* MI_ERR_INVALID_PARAM Invalid timer id supplied.
* MI_ERR_INVALID_STATE timer module has not been initialized or the
* timer is running.
* MI_ERR_NO_MEM timer pool is full.
*
* */
__WEAK mible_status_t mible_timer_create(void** p_timer_id,
mible_timer_handler timeout_handler, mible_timer_mode mode)
{
return MI_SUCCESS;
}
/**
* @brief Create a timer.
* @param [out] p_timer_id: a pointer to timer id address which can uniquely identify the timer.
* [in] timeout_handler: a pointer to a function which can be
* called when the timer expires.
* [in] mode: repeated or single shot.
* @return MI_SUCCESS If the timer was successfully created.
* MI_ERR_INVALID_PARAM Invalid timer id supplied.
* MI_ERR_INVALID_STATE timer module has not been initialized or the
* timer is running.
* MI_ERR_NO_MEM timer pool is full.
*
* */
__WEAK mible_status_t mible_user_timer_create(void** p_timer_id,
mible_timer_handler timeout_handler, mible_timer_mode mode)
{
return MI_SUCCESS;
}
/**
* @brief Delete a timer.
* @param [in] timer_id: timer id
* @return MI_SUCCESS If the timer was successfully deleted.
* MI_ERR_INVALID_PARAM Invalid timer id supplied..
* */
__WEAK mible_status_t mible_timer_delete(void* timer_id)
{
return MI_SUCCESS;
}
/**
* @brief Start a timer.
* @param [in] timer_id: timer id
* [in] timeout_value: Number of milliseconds to time-out event
* (minimum 10 ms).
* [in] p_context: parameters that can be passed to
* timeout_handler
*
* @return MI_SUCCESS If the timer was successfully started.
* MI_ERR_INVALID_PARAM Invalid timer id supplied.
* MI_ERR_INVALID_STATE If the application timer module has not been
* initialized or the timer has not been created.
* MI_ERR_NO_MEM If the timer operations queue was full.
* @note If the timer has already started, it will start counting again.
* */
__WEAK mible_status_t mible_timer_start(void* timer_id, uint32_t timeout_value,
void* p_context)
{
return MI_SUCCESS;
}
/**
* @brief Stop a timer.
* @param [in] timer_id: timer id
* @return MI_SUCCESS If the timer was successfully stopped.
* MI_ERR_INVALID_PARAM Invalid timer id supplied.
*
* */
__WEAK mible_status_t mible_timer_stop(void* timer_id)
{
return MI_SUCCESS;
}
/**
* NVM APIs
*/
/**
* @brief Create a record in flash
* @param [in] record_id: identify a record in flash
* [in] len: record length
* @return MI_SUCCESS Create successfully.
* MI_ERR_INVALID_LENGTH Size was 0, or higher than the maximum
*allowed size.
* MI_ERR_NO_MEM, Not enough flash memory to be assigned
*
* */
__WEAK mible_status_t mible_record_create(uint16_t record_id, uint8_t len)
{
return MI_SUCCESS;
}
/**
* @brief Delete a record in flash
* @param [in] record_id: identify a record in flash
* @return MI_SUCCESS Delete successfully.
* MI_ERR_INVALID_PARAMS Invalid record id supplied.
* */
__WEAK mible_status_t mible_record_delete(uint16_t record_id)
{
return MI_SUCCESS;
}
/**
* @brief Restore data to flash
* @param [in] record_id: identify an area in flash
* [out] p_data: pointer to data
* [in] len: data length
* @return MI_SUCCESS The command was accepted.
* MI_ERR_INVALID_LENGTH Size was 0, or higher than the maximum
*allowed size.
* MI_ERR_INVALID_PARAMS Invalid record id supplied.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* */
__WEAK mible_status_t mible_record_read(uint16_t record_id, uint8_t* p_data,
uint8_t len)
{
return MI_SUCCESS;
}
/**
* @brief Store data to flash
* @param [in] record_id: identify an area in flash
* [in] p_data: pointer to data
* [in] len: data length
* @return MI_SUCCESS The command was accepted.
* MI_ERR_INVALID_LENGTH Size was 0, or higher than the maximum
* allowed size.
* MI_ERR_INVALID_PARAMS p_data is not aligned to a 4 byte boundary.
* @note Should use asynchronous mode to implement this function.
* The data to be written to flash has to be kept in memory until the
* operation has terminated, i.e., an event is received.
* When record writing complete , call mible_arch_event_callback function and pass MIBLE_ARCH_EVT_RECORD_WRITE_CMP event and result.
* */
__WEAK mible_status_t mible_record_write(uint16_t record_id, const uint8_t* p_data,
uint8_t len)
{
return MI_SUCCESS;
}
/**
* MISC APIs
*/
/**
* @brief Get ture random bytes .
* @param [out] p_buf: pointer to data
* [in] len: Number of bytes to take from pool and place in
* p_buff
* @return MI_SUCCESS The requested bytes were written to
* p_buff
* MI_ERR_NO_MEM No bytes were written to the buffer, because
* there were not enough random bytes available.
* @note SHOULD use TRUE random num generator
* */
__WEAK mible_status_t mible_rand_num_generator(uint8_t* p_buf, uint8_t len)
{
return MI_SUCCESS;
}
/**
* @brief Encrypts a block according to the specified parameters. 128-bit
* AES encryption. (zero padding)
* @param [in] key: encryption key
* [in] plaintext: pointer to plain text
* [in] plen: plain text length
* [out] ciphertext: pointer to cipher text
* @return MI_SUCCESS The encryption operation completed.
* MI_ERR_INVALID_ADDR Invalid pointer supplied.
* MI_ERR_INVALID_STATE Encryption module is not initialized.
* MI_ERR_INVALID_LENGTH Length bigger than 16.
* MI_ERR_BUSY Encryption module already in progress.
* @note SHOULD use synchronous mode to implement this function
* */
__WEAK mible_status_t mible_aes128_encrypt(const uint8_t* key,
const uint8_t* plaintext, uint8_t plen, uint8_t* ciphertext)
{
return MI_SUCCESS;
}
/**
* @brief Post a task to a task quene, which can be executed in a right place
* (maybe a task in RTOS or while(1) in the main function).
* @param [in] handler: a pointer to function
* [in] param: function parameters
* @return MI_SUCCESS Successfully put the handler to quene.
* MI_ERR_NO_MEM The task quene is full.
* MI_ERR_INVALID_PARAM Handler is NULL
* */
__WEAK mible_status_t mible_task_post(mible_handler_t handler, void *arg)
{
return MI_SUCCESS;
}
/**
* @brief Function for executing all enqueued tasks.
*
* @note This function must be called from within the main loop. It will
* execute all events scheduled since the last time it was called.
* */
__WEAK void mible_tasks_exec(void)
{
}
/**
* IIC APIs
*/
/**
* @brief Function for initializing the IIC driver instance.
* @param [in] p_config: Pointer to the initial configuration.
* [in] handler: Event handler provided by the user.
* @return MI_SUCCESS Initialized successfully.
* MI_ERR_INVALID_PARAM p_config or handler is a NULL pointer.
*
* */
__WEAK mible_status_t mible_iic_init(const iic_config_t * p_config,
mible_handler_t handler)
{
return MI_SUCCESS;
}
/**
* @brief Function for uninitializing the IIC driver instance.
*
*
* */
__WEAK void mible_iic_uninit(void)
{
}
/**
* @brief Function for sending data to a IIC slave.
* @param [in] addr: Address of a specific slave device (only 7 LSB).
* [in] p_out: Pointer to tx data
* [in] len: Data length
* [in] no_stop: If set, the stop condition is not generated on the bus
* after the transfer has completed successfully (allowing for a repeated start in the next transfer).
* @return MI_SUCCESS The command was accepted.
* MI_ERR_BUSY If a transfer is ongoing.
* MI_ERR_INVALID_PARAM p_out is not vaild address.
* @note This function should be implemented in non-blocking mode.
* When tx procedure complete, the handler provided by mible_iic_init() should be called,
* and the iic event should be passed as a argument.
* */
__WEAK mible_status_t mible_iic_tx(uint8_t addr, uint8_t * p_out, uint16_t len,
bool no_stop)
{
return MI_SUCCESS;
}
/**
* @brief Function for receiving data from a IIC slave.
* @param [in] addr: Address of a specific slave device (only 7 LSB).
* [out] p_in: Pointer to rx data
* [in] len: Data length
* @return MI_SUCCESS The command was accepted.
* MI_ERR_BUSY If a transfer is ongoing.
* MI_ERR_INVALID_PARAM p_in is not vaild address.
* @note This function should be implemented in non-blocking mode.
* When rx procedure complete, the handler provided by mible_iic_init() should be called,
* and the iic event should be passed as a argument.
* */
__WEAK mible_status_t mible_iic_rx(uint8_t addr, uint8_t * p_in, uint16_t len)
{
return MI_SUCCESS;
}
/**
* @brief Function for checking IIC SCL pin.
* @param [in] port: SCL port
* [in] pin : SCL pin
* @return 1: High (Idle)
* 0: Low (Busy)
* */
__WEAK int mible_iic_scl_pin_read(uint8_t port, uint8_t pin)
{
return 0;
}
__WEAK mible_status_t mible_nvm_init(void)
{
return MI_SUCCESS;
}
/**
* @brief Function for reading data from Non-Volatile Memory.
* @param [out] p_data: Pointer to data to be restored.
* [in] length: Data size in bytes.
* [in] address: Address in Non-Volatile Memory to read.
* @return MI_ERR_INTERNAL: invalid NVM address.
* MI_SUCCESS
* */
__WEAK mible_status_t mible_nvm_read(void * p_data, uint32_t length, uint32_t address)
{
return MI_ERR_BUSY;
}
/**
* @brief Writes data to Non-Volatile Memory.
* @param [in] p_data: Pointer to data to be stored.
* [in] length: Data size in bytes.
* [in] address: Start address used to store data.
* @return MI_ERR_INTERNAL: invalid NVM address.
* MI_SUCCESS
* */
__WEAK mible_status_t mible_nvm_write(void * p_data, uint32_t length, uint32_t address)
{
return MI_ERR_BUSY;
}
__WEAK mible_status_t mible_upgrade_firmware(void)
{
return MI_ERR_BUSY;
}
/**
*@brief reboot device.
*@return 0: success, negetive value: failure
*/
__WEAK mible_status_t mible_reboot(void)
{
return MI_ERR_BUSY;
}
/**
*@brief set node tx power.
*@param [in] power : TX power in 0.1 dBm steps.
*@return 0: success, negetive value: failure
*/
__WEAK mible_status_t mible_set_tx_power(int16_t power)
{
return MI_SUCCESS;
}
__WEAK int mible_log_printf(const char * sFormat, ...)
{
return MI_SUCCESS;
}
__WEAK int mible_log_hexdump(void* array_base, uint16_t array_size)
{
return MI_SUCCESS;
}