1 /******************************************************************************
2  *
3  *  Copyright 2014 Google, Inc.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 #include <stdbool.h>
22 #include <stddef.h>
23 #include <stdint.h>
24 
25 // Provides Class Of Device primitive as specified in the bluetooth spec.
26 // [Class Of Device]
27 // (https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband)
28 
29 // Device class may be defined in other structures.
30 // Only use defined methods to manipulate internals.
31 typedef struct bt_device_class_t {
32   uint8_t _[3];  // Do not access directly; use methods below.
33 } bt_device_class_t;
34 
35 // Copies the |data| class of device stream into device class |dc|.  |dc|
36 // and |data| must not be NULL.
37 void device_class_from_stream(bt_device_class_t* dc, const uint8_t* data);
38 
39 // Serializes the device class |dc| to pointer argument |data| in big endian
40 // format.  |len| must contain the buffer size of |data|.  Returns the actual
41 // number of bytes copied into |data|.  |dc| and |data| must not be NULL.
42 int device_class_to_stream(const bt_device_class_t* dc, uint8_t* data,
43                            size_t len);
44 
45 // Copies the |data| class of device integer into device class |dc|.  |dc|
46 // must not be NULL.
47 void device_class_from_int(bt_device_class_t* dc, int data);
48 
49 // Returns the device class |dc| in integer format.  |dc| must not be NULL.
50 int device_class_to_int(const bt_device_class_t* dc);
51 
52 // Compares and returns |true| if two device classes |p1| and |p2| are equal.
53 // False otherwise.
54 bool device_class_equals(const bt_device_class_t* p1,
55                          const bt_device_class_t* p2);
56 
57 // Copies and returns |true| if the device class was successfully copied from
58 //  |p2| into |p1|.  False otherwise.
59 bool device_class_copy(bt_device_class_t* dest, const bt_device_class_t* src);
60 
61 // Query, getters and setters for the major device class.  |dc| must not be
62 // NULL.
63 int device_class_get_major_device(const bt_device_class_t* dc);
64 void device_class_set_major_device(bt_device_class_t* dc, int val);
65 
66 // Query, getters and setters for the minor device class. |dc| must not be NULL.
67 int device_class_get_minor_device(const bt_device_class_t* dc);
68 void device_class_set_minor_device(bt_device_class_t* dc, int val);
69 
70 // Query, getters and setters for the various major service class features.
71 // |dc| must not be NULL.
72 bool device_class_get_limited(const bt_device_class_t* dc);
73 void device_class_set_limited(bt_device_class_t* dc, bool set);
74 
75 bool device_class_get_positioning(const bt_device_class_t* dc);
76 void device_class_set_positioning(bt_device_class_t* dc, bool set);
77 
78 bool device_class_get_networking(const bt_device_class_t* dc);
79 void device_class_set_networking(bt_device_class_t* dc, bool set);
80 
81 bool device_class_get_rendering(const bt_device_class_t* dc);
82 void device_class_set_rendering(bt_device_class_t* dc, bool set);
83 
84 bool device_class_get_capturing(const bt_device_class_t* dc);
85 void device_class_set_capturing(bt_device_class_t* dc, bool set);
86 
87 bool device_class_get_object_transfer(const bt_device_class_t* dc);
88 void device_class_set_object_transfer(bt_device_class_t* dc, bool set);
89 
90 bool device_class_get_audio(const bt_device_class_t* dc);
91 void device_class_set_audio(bt_device_class_t* dc, bool set);
92 
93 bool device_class_get_telephony(const bt_device_class_t* dc);
94 void device_class_set_telephony(bt_device_class_t* dc, bool set);
95 
96 bool device_class_get_information(const bt_device_class_t* dc);
97 void device_class_set_information(bt_device_class_t* dc, bool set);
98