xref: /haiku/headers/private/bluetooth/CodeHandler.h (revision d923116745d1521f69bb90cd4e5660a91d93c88d)
1 #ifndef _CODEHANDLER_H_
2 #define _CODEHANDLER_H_
3 
4 #include <bluetooth/HCI/btHCI.h>
5 
6 namespace Bluetooth
7 {
8 
9 class CodeHandler {
10 
11 public:
12 	/*
13 	 * TODO: Handler and protocol could be fit in 16 bits 12
14 	 * for handler and 4 for the protocol
15 	 */
16 
17 	/*
18 	 * Used:
19 	 * - From HCI layer to send events to bluetooth server.
20 	 * - L2cap lower to dispatch TX packets to HCI Layer
21 	 * - informing about connection handle
22 	 * - Transport drivers dispatch its data to HCI layer
23 	 *
24 	 */
Device(uint32 code)25 	static hci_id Device(uint32 code)
26 	{
27 		return ((code & 0xFF000000) >> 24);
28 	}
29 
30 
SetDevice(uint32 * code,hci_id device)31 	static void SetDevice(uint32* code, hci_id device)
32 	{
33 		*code = *code | ((device & 0xFF) << 24);
34 	}
35 
36 
Handler(uint32 code)37 	static uint16 Handler(uint32 code)
38 	{
39 		return ((code & 0xFFFF) >> 0);
40 	}
41 
42 
SetHandler(uint32 * code,uint16 handler)43 	static void SetHandler(uint32* code, uint16 handler)
44 	{
45 		*code = *code | ((handler & 0xFFFF) << 0);
46 	}
47 
48 
Protocol(uint32 code)49 	static bt_packet_t Protocol(uint32 code)
50 	{
51 		return (bt_packet_t)((code & 0xFF0000) >> 16);
52 	}
53 
54 
SetProtocol(uint32 * code,bt_packet_t protocol)55 	static void SetProtocol(uint32* code, bt_packet_t protocol)
56 	{
57 		*code = *code | ((protocol & 0xFF) << 16);
58 	}
59 
60 
61 };
62 
63 
64 } // namespace
65 
66 
67 #endif
68