1 /* main.c - Application main entry point */
2 
3 /*
4  * Copyright (c) 2015-2016 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <zephyr/types.h>
10 #include <stddef.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <zephyr/sys/printk.h>
14 #include <zephyr/sys/byteorder.h>
15 #include <zephyr/kernel.h>
16 
17 #include <zephyr/bluetooth/bluetooth.h>
18 #include <zephyr/bluetooth/conn.h>
19 #include <zephyr/bluetooth/hfp_hf.h>
20 
connected(struct bt_conn * conn)21 static void connected(struct bt_conn *conn)
22 {
23 	printk("HFP HF Connected!\n");
24 }
25 
disconnected(struct bt_conn * conn)26 static void disconnected(struct bt_conn *conn)
27 {
28 	printk("HFP HF Disconnected!\n");
29 }
30 
service(struct bt_conn * conn,uint32_t value)31 static void service(struct bt_conn *conn, uint32_t value)
32 {
33 	printk("Service indicator value: %u\n", value);
34 }
35 
call(struct bt_conn * conn,uint32_t value)36 static void call(struct bt_conn *conn, uint32_t value)
37 {
38 	printk("Call indicator value: %u\n", value);
39 }
40 
call_setup(struct bt_conn * conn,uint32_t value)41 static void call_setup(struct bt_conn *conn, uint32_t value)
42 {
43 	printk("Call Setup indicator value: %u\n", value);
44 }
45 
call_held(struct bt_conn * conn,uint32_t value)46 static void call_held(struct bt_conn *conn, uint32_t value)
47 {
48 	printk("Call Held indicator value: %u\n", value);
49 }
50 
signal(struct bt_conn * conn,uint32_t value)51 static void signal(struct bt_conn *conn, uint32_t value)
52 {
53 	printk("Signal indicator value: %u\n", value);
54 }
55 
roam(struct bt_conn * conn,uint32_t value)56 static void roam(struct bt_conn *conn, uint32_t value)
57 {
58 	printk("Roaming indicator value: %u\n", value);
59 }
60 
battery(struct bt_conn * conn,uint32_t value)61 static void battery(struct bt_conn *conn, uint32_t value)
62 {
63 	printk("Battery indicator value: %u\n", value);
64 }
65 
ring_cb(struct bt_conn * conn)66 static void ring_cb(struct bt_conn *conn)
67 {
68 	printk("Incoming Call...\n");
69 }
70 
71 static struct bt_hfp_hf_cb hf_cb = {
72 	.connected = connected,
73 	.disconnected = disconnected,
74 	.service = service,
75 	.call = call,
76 	.call_setup = call_setup,
77 	.call_held = call_held,
78 	.signal = signal,
79 	.roam = roam,
80 	.battery = battery,
81 	.ring_indication = ring_cb,
82 };
83 
bt_ready(int err)84 static void bt_ready(int err)
85 {
86 	if (err) {
87 		printk("Bluetooth init failed (err %d)\n", err);
88 		return;
89 	}
90 
91 	printk("Bluetooth initialized\n");
92 
93 	err = bt_br_set_connectable(true);
94 	if (err) {
95 		printk("BR/EDR set/rest connectable failed (err %d)\n", err);
96 		return;
97 	}
98 	err = bt_br_set_discoverable(true);
99 	if (err) {
100 		printk("BR/EDR set discoverable failed (err %d)\n", err);
101 		return;
102 	}
103 
104 	printk("BR/EDR set connectable and discoverable done\n");
105 }
106 
handsfree_enable(void)107 static void handsfree_enable(void)
108 {
109 	int err;
110 
111 	err = bt_hfp_hf_register(&hf_cb);
112 	if (err < 0) {
113 		printk("HFP HF Registration failed (err %d)\n", err);
114 	}
115 }
116 
main(void)117 int main(void)
118 {
119 	int err;
120 
121 	handsfree_enable();
122 
123 	err = bt_enable(bt_ready);
124 	if (err) {
125 		printk("Bluetooth init failed (err %d)\n", err);
126 	}
127 	return 0;
128 }
129