1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "hci_evt_cmd_complete.h"
17 
18 #include <string.h>
19 
20 #include "platform/include/allocator.h"
21 #include "platform/include/list.h"
22 #include "platform/include/mutex.h"
23 
24 #include "hci/cmd/hci_cmd.h"
25 #include "hci/hci.h"
26 #include "hci/hci_def.h"
27 
28 #include "hci_evt_controller_baseband_cmd_complete.h"
29 #include "hci_evt_info_params_cmd_complete.h"
30 #include "hci_evt_le_cmd_complete.h"
31 #include "hci_evt_link_ctrl_cmd_complete.h"
32 #include "hci_evt_link_policy_cmd_complete.h"
33 #include "hci_evt_status_params_cmd_complete.h"
34 #include "hci_vendor_if.h"
35 
HciEventOnCommandCompleteEvent(Packet * packet)36 void HciEventOnCommandCompleteEvent(Packet *packet)
37 {
38     Buffer *payloadBuffer = PacketContinuousPayload(packet);
39     if (payloadBuffer == NULL) {
40         return;
41     }
42 
43     if (BufferGetSize(payloadBuffer) < sizeof(HciCommandCompleteEventParam)) {
44         return;
45     }
46 
47     HciCommandCompleteEventParam *param = (HciCommandCompleteEventParam *)BufferPtr(payloadBuffer);
48     if (param == NULL) {
49         return;
50     }
51     HciSetNumberOfHciCmd(param->numHciCommandPackets);
52     HciCmdOnCommandComplete(param->commandOpcode);
53 
54     uint8_t returnParametesLength = BufferGetSize(payloadBuffer) - sizeof(HciCommandCompleteEventParam);
55     if (returnParametesLength == 0) {
56         return;
57     }
58     const void *returnParametes = (uint8_t *)param + sizeof(HciCommandCompleteEventParam);
59 
60     switch (GET_OGF(param->commandOpcode)) {
61         case HCI_COMMAND_OGF_LINK_CONTROL:
62             HciEventOnLinkControlCommandComplete(param->commandOpcode, returnParametes, returnParametesLength);
63             break;
64         case HCI_COMMAND_OGF_LINK_POLICY:
65             HciEventOnLinkPolicyCommandComplete(param->commandOpcode, returnParametes, returnParametesLength);
66             break;
67         case HCI_COMMAND_OGF_CONTTOLLER_AND_BASEBAND:
68             HciEventOnControllerBasebandCommandComplete(param->commandOpcode, returnParametes, returnParametesLength);
69             break;
70         case HCI_COMMAND_OGF_INFORMATIONAL_PARAMETERS:
71             HciEventOnInformationalParametersCommandComplete(
72                 param->commandOpcode, returnParametes, returnParametesLength);
73             break;
74         case HCI_COMMAND_OGF_STATUS_PARAMETERS:
75             HciEventOnStatusParametersCommandComplete(param->commandOpcode, returnParametes, returnParametesLength);
76             break;
77         case HCI_COMMAND_OGF_LE_CONTROLLER:
78             HciEventOnLeCommandComplete(param->commandOpcode, returnParametes, returnParametesLength);
79             break;
80         case HCI_COMMAND_OGF_VENDOR_SPECIFIC:
81             HciEventOnVendorCommandComplete(param->commandOpcode, returnParametes, returnParametesLength);
82             break;
83         default:
84             break;
85     }
86 }