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, size_t len);
43 
44 // Copies the |data| class of device integer into device class |dc|.  |dc|
45 // must not be NULL.
46 void device_class_from_int(bt_device_class_t* dc, int data);
47 
48 // Returns the device class |dc| in integer format.  |dc| must not be NULL.
49 int device_class_to_int(const bt_device_class_t* dc);
50 
51 // Compares and returns |true| if two device classes |p1| and |p2| are equal.
52 // False otherwise.
53 bool device_class_equals(const bt_device_class_t* p1, const bt_device_class_t* p2);
54 
55 // Copies and returns |true| if the device class was successfully copied from
56 //  |p2| into |p1|.  False otherwise.
57 bool device_class_copy(bt_device_class_t* dest, const bt_device_class_t* src);
58 
59 // Query, getters and setters for the major device class.  |dc| must not be
60 // NULL.
61 int device_class_get_major_device(const bt_device_class_t* dc);
62 void device_class_set_major_device(bt_device_class_t* dc, int val);
63 
64 // Query, getters and setters for the minor device class. |dc| must not be NULL.
65 int device_class_get_minor_device(const bt_device_class_t* dc);
66 void device_class_set_minor_device(bt_device_class_t* dc, int val);
67 
68 // Query, getters and setters for the various major service class features.
69 // |dc| must not be NULL.
70 bool device_class_get_limited(const bt_device_class_t* dc);
71 void device_class_set_limited(bt_device_class_t* dc, bool set);
72 
73 bool device_class_get_positioning(const bt_device_class_t* dc);
74 void device_class_set_positioning(bt_device_class_t* dc, bool set);
75 
76 bool device_class_get_networking(const bt_device_class_t* dc);
77 void device_class_set_networking(bt_device_class_t* dc, bool set);
78 
79 bool device_class_get_rendering(const bt_device_class_t* dc);
80 void device_class_set_rendering(bt_device_class_t* dc, bool set);
81 
82 bool device_class_get_capturing(const bt_device_class_t* dc);
83 void device_class_set_capturing(bt_device_class_t* dc, bool set);
84 
85 bool device_class_get_object_transfer(const bt_device_class_t* dc);
86 void device_class_set_object_transfer(bt_device_class_t* dc, bool set);
87 
88 bool device_class_get_audio(const bt_device_class_t* dc);
89 void device_class_set_audio(bt_device_class_t* dc, bool set);
90 
91 bool device_class_get_telephony(const bt_device_class_t* dc);
92 void device_class_set_telephony(bt_device_class_t* dc, bool set);
93 
94 bool device_class_get_information(const bt_device_class_t* dc);
95 void device_class_set_information(bt_device_class_t* dc, bool set);
96