Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / controller / python / ChipDeviceController-ScriptDevicePairingDelegate.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2013-2017 Nest Labs, Inc.
5  *    All rights reserved.
6  *
7  *    Licensed under the Apache License, Version 2.0 (the "License");
8  *    you may not use this file except in compliance with the License.
9  *    You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *    Unless required by applicable law or agreed to in writing, software
14  *    distributed under the License is distributed on an "AS IS" BASIS,
15  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *    See the License for the specific language governing permissions and
17  *    limitations under the License.
18  */
19
20 #include "ChipDeviceController-ScriptDevicePairingDelegate.h"
21
22 #include <transport/RendezvousSessionDelegate.h>
23
24 namespace chip {
25 namespace Controller {
26
27 void ScriptDevicePairingDelegate::SetWifiCredential(const char * ssid, const char * password)
28 {
29     strncpy(mWifiSSID, ssid, sizeof(mWifiSSID));
30     strncpy(mWifiPassword, password, sizeof(mWifiPassword));
31     mMode = Mode::Wifi;
32 }
33
34 void ScriptDevicePairingDelegate::SetThreadCredential(uint8_t channel, uint16_t panId,
35                                                       uint8_t (&masterKey)[chip::DeviceLayer::Internal::kThreadMasterKeyLength])
36 {
37     mThreadInfo               = {};
38     mThreadInfo.ThreadChannel = channel;
39     mThreadInfo.ThreadPANId   = panId;
40     memcpy(mThreadInfo.ThreadMasterKey, masterKey, sizeof(masterKey));
41     mMode = Mode::Thread;
42 }
43
44 void ScriptDevicePairingDelegate::OnNetworkCredentialsRequested(RendezvousDeviceCredentialsDelegate * callback)
45 {
46     if (mMode == Mode::Wifi)
47         callback->SendNetworkCredentials(mWifiSSID, mWifiPassword);
48     else
49         callback->SendThreadCredentials(mThreadInfo);
50 }
51
52 void ScriptDevicePairingDelegate::OnOperationalCredentialsRequested(const char * csr, size_t csr_length,
53                                                                     RendezvousDeviceCredentialsDelegate * callback)
54 {
55     // TODO: Implement this
56     ChipLogDetail(Controller, "ScriptDevicePairingDelegate::OnOperationalCredentialsRequested\n");
57 }
58
59 void ScriptDevicePairingDelegate::SetKeyExchangeCallback(DevicePairingDelegate_OnPairingCompleteFunct callback)
60 {
61     mOnPairingCompleteCallback = callback;
62 }
63
64 void ScriptDevicePairingDelegate::OnPairingComplete(CHIP_ERROR error)
65 {
66     if (mOnPairingCompleteCallback != nullptr)
67     {
68         mOnPairingCompleteCallback(error);
69     }
70 }
71
72 } // namespace Controller
73 } // namespace chip