command_packet.h revision f3b1820e1676261886a6537e1f6abac6a35ed6d4
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 "vendor_libs/test_vendor_lib/include/packet.h"
20
21#include <cstdint>
22#include <vector>
23
24#include <base/macros.h>
25
26namespace test_vendor_lib {
27
28// The following is specified in the Bluetooth Core Specification Version 4.2,
29// Volume 2, Part E, Section 5.4.1 (page 470). Command Packets begin with a 3
30// octet header formatted as follows:
31// - Opcode: 2 octets
32//   - Opcode Group Field (OGF): Upper bits 10-15
33//   - Opcode Command Field (OCF): Lower bits 0-9
34// - Payload size (in octets): 1 octet
35// The header is followed by the payload, which contains command specific
36// parameters and has a maximum size of 255 octets. Valid command opcodes are
37// defined in stack/include/hcidefs.h. The OGF ranges from 0x00 to 0x3F, with
38// 0x3F reserved for vendor-specific debug functions. The OCF ranges from
39// 0x0000 to 0x03FF. Note that the payload size is the size in octets of the
40// command parameters and not the number of parameters. Finally, although the
41// parameters contained in the payload are command specific (including the size
42// and number of parameters), each parameter will be an integer number of octets
43// in size.
44class CommandPacket : public Packet {
45 public:
46  CommandPacket();
47
48  ~CommandPacket() override = default;
49
50  // Returns the command opcode as defined in stack/include/hcidefs.h.
51  // See the Bluetooth Core Specification Version 4.2, Volume 2, Part E,
52  // Section 7 for more information about each HCI commands and for a listing
53  // of their specific opcodes/OGF and OCF values.
54  std::uint16_t GetOpcode() const;
55
56  // Returns the 6 bit opcode group field that specifies the general category of
57  // the command. The OGF can be one of seven values:
58  // - 0x01: Link control commands
59  // - 0x02: Link policy commands
60  // - 0x03: Controller and baseband commands
61  // - 0x04: Informational parameters commands
62  // - 0x05: Status parameters commands
63  // - 0x06: Testing commands
64  // - 0x08: Low energy controller commands
65  // The upper 2 bits will be zero filled.
66  std::uint8_t GetOGF() const;
67
68  // Returns the 10 bit opcode command field that specifies an exact command
69  // within an opcode group field. The upper 6 bits will be zero filled.
70  std::uint16_t GetOCF() const;
71
72  // Size in octets of a command packet header, which consists of a 2 octet
73  // opcode and a 1 octet payload size.
74  static const size_t kCommandHeaderSize = 3;
75
76 private:
77  // Disallow any copies of the singleton to be made.
78  DISALLOW_COPY_AND_ASSIGN(CommandPacket);
79};
80
81}  // namespace test_vendor_lib
82