1 /* btp_ias.c - Bluetooth IAS Server Tester */
2
3 /*
4 * Copyright (c) 2022 Codecoup
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8 #include <zephyr/bluetooth/services/ias.h>
9
10 #include "btp/btp.h"
11 #include <zephyr/sys/byteorder.h>
12 #include <stdint.h>
13
14 #include <zephyr/logging/log.h>
15 #define LOG_MODULE_NAME bttester_ias
16 LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL);
17
18 static bool initialized;
19
20
21 /* Immediate Alert Service */
alert_stop(void)22 static void alert_stop(void)
23 {
24 struct btp_ias_alert_action_ev ev;
25
26 if (!initialized) {
27 return;
28 }
29
30 ev.alert_lvl = BT_IAS_ALERT_LVL_NO_ALERT;
31
32 tester_event(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION,
33 (uint8_t *)&ev, sizeof(ev));
34 }
35
alert_start(void)36 static void alert_start(void)
37 {
38 struct btp_ias_alert_action_ev ev;
39
40 if (!initialized) {
41 return;
42 }
43
44 ev.alert_lvl = BT_IAS_ALERT_LVL_MILD_ALERT;
45
46 tester_event(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, &ev, sizeof(ev));
47 }
48
alert_high_start(void)49 static void alert_high_start(void)
50 {
51 struct btp_ias_alert_action_ev ev;
52
53 if (!initialized) {
54 return;
55 }
56
57 ev.alert_lvl = BT_IAS_ALERT_LVL_HIGH_ALERT;
58
59 tester_event(BTP_SERVICE_ID_IAS, BTP_IAS_EV_OUT_ALERT_ACTION, &ev, sizeof(ev));
60 }
61
62 BT_IAS_CB_DEFINE(ias_callbacks) = {
63 .no_alert = alert_stop,
64 .mild_alert = alert_start,
65 .high_alert = alert_high_start,
66 };
67
tester_init_ias(void)68 uint8_t tester_init_ias(void)
69 {
70 initialized = true;
71
72 return BTP_STATUS_SUCCESS;
73 }
74
tester_unregister_ias(void)75 uint8_t tester_unregister_ias(void)
76 {
77 initialized = false;
78
79 return BTP_STATUS_SUCCESS;
80 }
81