10bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton/****************************************************************************** 20bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * 30bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * Copyright (C) 2014 Google, Inc. 40bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * 50bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * Licensed under the Apache License, Version 2.0 (the "License"); 60bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * you may not use this file except in compliance with the License. 70bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * You may obtain a copy of the License at: 80bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * 90bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * http://www.apache.org/licenses/LICENSE-2.0 100bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * 110bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * Unless required by applicable law or agreed to in writing, software 120bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * distributed under the License is distributed on an "AS IS" BASIS, 130bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 140bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * See the License for the specific language governing permissions and 150bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * limitations under the License. 160bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton * 170bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton ******************************************************************************/ 180bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 190bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton#pragma once 200bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 210bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton#include <stdbool.h> 220bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton#include <stdint.h> 230bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 240bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Provides Class Of Device primitive as specified in the bluetooth spec. 250bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// [Class Of Device](https://www.bluetooth.org/en-us/specification/assigned-numbers/baseband) 260bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 270bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Device class may be defined in other structures. 280bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Only use defined methods to manipulate internals. 290bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantontypedef struct bt_device_class_t { 300bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton uint8_t _[3]; // Do not access directly; use methods below. 310bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton} bt_device_class_t; 320bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 330bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Copies the |data| class of device stream into device class |dc|. |dc| 340bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// and |data| must not be NULL. 350bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_from_stream(bt_device_class_t *dc, const uint8_t *data); 360bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 370bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Serializes the device class |dc| to pointer argument |data| in big endian 380bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// format. |len| must contain the buffer size of |data|. Returns the actual 390bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// number of bytes copied into |data|. |dc| and |data| must not be NULL. 400bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonint device_class_to_stream(const bt_device_class_t *dc, uint8_t *data, size_t len); 410bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 420bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Copies the |data| class of device integer into device class |dc|. |dc| 430bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// must not be NULL. 440bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_from_int(bt_device_class_t *dc, int data); 450bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 460bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Returns the device class |dc| in integer format. |dc| must not be NULL. 470bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonint device_class_to_int(const bt_device_class_t *dc); 480bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 490bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Compares and returns |true| if two device classes |p1| and |p2| are equal. 500bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// False otherwise. 510bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_equals(const bt_device_class_t *p1, const bt_device_class_t *p2); 520bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 530bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Copies and returns |true| if the device class was successfully copied from 540bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// |p2| into |p1|. False otherwise. 550bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_copy(bt_device_class_t *dest, const bt_device_class_t *src); 560bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 570bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Query, getters and setters for the major device class. |dc| must not be NULL. 580bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonint device_class_get_major_device(const bt_device_class_t *dc); 590bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_major_device(bt_device_class_t *dc, int val); 600bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 610bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Query, getters and setters for the minor device class. |dc| must not be NULL. 620bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonint device_class_get_minor_device(const bt_device_class_t *dc); 630bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_minor_device(bt_device_class_t *dc, int val); 640bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 650bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// Query, getters and setters for the various major service class features. 660bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton// |dc| must not be NULL. 670bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_limited(const bt_device_class_t *dc); 680bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_limited(bt_device_class_t *dc, bool set); 690bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 700bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_positioning(const bt_device_class_t *dc); 710bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_positioning(bt_device_class_t *dc, bool set); 720bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 730bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_networking(const bt_device_class_t *dc); 740bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_networking(bt_device_class_t *dc, bool set); 750bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 760bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_rendering(const bt_device_class_t *dc); 770bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_rendering(bt_device_class_t *dc, bool set); 780bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 790bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_capturing(const bt_device_class_t *dc); 800bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_capturing(bt_device_class_t *dc, bool set); 810bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 820bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_object_transfer(const bt_device_class_t *dc); 830bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_object_transfer(bt_device_class_t *dc, bool set); 840bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 850bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_audio(const bt_device_class_t *dc); 860bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_audio(bt_device_class_t *dc, bool set); 870bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 880bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_telephony(const bt_device_class_t *dc); 890bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_telephony(bt_device_class_t *dc, bool set); 900bc7d271d839c7f0346437dee39d679d38b6c9ecChris Manton 910bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonbool device_class_get_information(const bt_device_class_t *dc); 920bc7d271d839c7f0346437dee39d679d38b6c9ecChris Mantonvoid device_class_set_information(bt_device_class_t *dc, bool set); 93