• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 namespace bluetooth {
20 namespace hci {
21 namespace acl_manager {
22 
23 template <class T>
check_command_complete(CommandCompleteView view)24 void check_command_complete(CommandCompleteView view) {
25   ASSERT(view.IsValid());
26   auto status_view = T::Create(view);
27   if (!status_view.IsValid()) {
28     LOG_ERROR("Received command complete with invalid packet, opcode 0x%02hx", view.GetCommandOpCode());
29     return;
30   }
31   ErrorCode status = status_view.GetStatus();
32   OpCode op_code = status_view.GetCommandOpCode();
33   if (status != ErrorCode::SUCCESS) {
34     std::string error_code = ErrorCodeText(status);
35     LOG_ERROR("Received command complete with error code %s, opcode 0x%02hx", error_code.c_str(), op_code);
36     return;
37   }
38 }
39 
40 template <class T>
check_command_status(CommandStatusView view)41 void check_command_status(CommandStatusView view) {
42   ASSERT(view.IsValid());
43   auto status_view = T::Create(view);
44   if (!status_view.IsValid()) {
45     LOG_ERROR("Received command status with invalid packet, opcode 0x%02hx", view.GetCommandOpCode());
46     return;
47   }
48   ErrorCode status = status_view.GetStatus();
49   OpCode op_code = status_view.GetCommandOpCode();
50   if (status != ErrorCode::SUCCESS) {
51     std::string error_code = ErrorCodeText(status);
52     LOG_ERROR("Received command status with error code %s, opcode 0x%02hx", error_code.c_str(), op_code);
53     return;
54   }
55 }
56 
57 }  // namespace acl_manager
58 }  // namespace hci
59 }  // namespace bluetooth
60