• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #pragma once
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include "base/macros.h"
23 #include "vendor_libs/test_vendor_lib/include/packet.h"
24 
25 namespace test_vendor_lib {
26 
27 // The following is specified in the Bluetooth Core Specification Version 4.2,
28 // Volume 2, Part E, Section 5.4.1 (page 470). Command Packets begin with a 3
29 // octet header formatted as follows:
30 // - Opcode: 2 octets
31 //   - Opcode Group Field (OGF): Upper bits 10-15
32 //   - Opcode Command Field (OCF): Lower bits 0-9
33 // - Payload size (in octets): 1 octet
34 // The header is followed by the payload, which contains command specific
35 // parameters and has a maximum size of 255 octets. Valid command opcodes are
36 // defined in stack/include/hcidefs.h. The OGF ranges from 0x00 to 0x3F, with
37 // 0x3F reserved for vendor-specific debug functions. The OCF ranges from
38 // 0x0000 to 0x03FF. Note that the payload size is the size in octets of the
39 // command parameters and not the number of parameters. Finally, although the
40 // parameters contained in the payload are command specific (including the size
41 // and number of parameters), each parameter will be an integer number of octets
42 // in size.
43 class CommandPacket : public Packet {
44  public:
45   CommandPacket();
46 
47   virtual ~CommandPacket() override = default;
48 
49   // Returns the command opcode as defined in stack/include/hcidefs.h.
50   // See the Bluetooth Core Specification Version 4.2, Volume 2, Part E,
51   // Section 7 for more information about each HCI commands and for a listing
52   // of their specific opcodes/OGF and OCF values.
53   uint16_t GetOpcode() const;
54 
55   // Returns the 6 bit opcode group field that specifies the general category of
56   // the command. The OGF can be one of seven values:
57   // - 0x01: Link control commands
58   // - 0x02: Link policy commands
59   // - 0x03: Controller and baseband commands
60   // - 0x04: Informational parameters commands
61   // - 0x05: Status parameters commands
62   // - 0x06: Testing commands
63   // - 0x08: Low energy controller commands
64   // The upper 2 bits will be zero filled.
65   uint8_t GetOGF() const;
66 
67   // Returns the 10 bit opcode command field that specifies an exact command
68   // within an opcode group field. The upper 6 bits will be zero filled.
69   uint16_t GetOCF() const;
70 
71   // Size in octets of a command packet header, which consists of a 2 octet
72   // opcode and a 1 octet payload size.
73   static const size_t kCommandHeaderSize = 3;
74 
75  private:
76   // Disallow any copies of the singleton to be made.
77   DISALLOW_COPY_AND_ASSIGN(CommandPacket);
78 };
79 
80 }  // namespace test_vendor_lib
81