|
66 | 66 | case PairingMode::Code:
|
67 | 67 | PairWithPayload(&error);
|
68 | 68 | break;
|
69 |
| - case PairingMode::Ethernet: |
70 |
| - PairWithIPAddress(&error); |
71 |
| - break; |
72 | 69 | case PairingMode::Ble:
|
73 | 70 | PairWithCode(&error);
|
74 | 71 | break;
|
|
83 | 80 | void PairingCommandBridge::PairWithCode(NSError * __autoreleasing * error)
|
84 | 81 | {
|
85 | 82 | SetUpPairingDelegate();
|
| 83 | + auto * payload = [[MTRSetupPayload alloc] initWithSetupPasscode:@(mSetupPINCode) discriminator:@(mDiscriminator)]; |
86 | 84 | MTRDeviceController * commissioner = CurrentCommissioner();
|
87 |
| - [commissioner pairDevice:mNodeId discriminator:mDiscriminator setupPINCode:mSetupPINCode error:error]; |
| 85 | + [commissioner setupCommissioningSessionWithPayload:payload newNodeID:@(mNodeId) error:error]; |
88 | 86 | }
|
89 | 87 |
|
90 | 88 | void PairingCommandBridge::PairWithPayload(NSError * __autoreleasing * error)
|
91 | 89 | {
|
92 |
| - NSString * payload = [NSString stringWithUTF8String:mOnboardingPayload]; |
93 |
| - |
94 |
| - SetUpPairingDelegate(); |
95 |
| - MTRDeviceController * commissioner = CurrentCommissioner(); |
96 |
| - [commissioner pairDevice:mNodeId onboardingPayload:payload error:error]; |
97 |
| -} |
98 |
| - |
99 |
| -void PairingCommandBridge::PairWithIPAddress(NSError * __autoreleasing * error) |
100 |
| -{ |
| 90 | + NSString * onboardingPayload = [NSString stringWithUTF8String:mOnboardingPayload]; |
101 | 91 | SetUpPairingDelegate();
|
| 92 | + auto * payload = [MTRSetupPayload setupPayloadWithOnboardingPayload:onboardingPayload error:error]; |
| 93 | + if (payload == nil) { |
| 94 | + return; |
| 95 | + } |
102 | 96 | MTRDeviceController * commissioner = CurrentCommissioner();
|
103 |
| - [commissioner pairDevice:mNodeId |
104 |
| - address:[NSString stringWithUTF8String:ipAddress] |
105 |
| - port:mRemotePort |
106 |
| - setupPINCode:mSetupPINCode |
107 |
| - error:error]; |
| 97 | + [commissioner setupCommissioningSessionWithPayload:payload newNodeID:@(mNodeId) error:error]; |
108 | 98 | }
|
109 | 99 |
|
110 | 100 | void PairingCommandBridge::Unpair()
|
111 | 101 | {
|
112 | 102 | dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip-tool.command", DISPATCH_QUEUE_SERIAL);
|
113 | 103 | MTRDeviceController * commissioner = CurrentCommissioner();
|
114 |
| - [commissioner |
115 |
| - getBaseDevice:mNodeId |
116 |
| - queue:callbackQueue |
117 |
| - completion:^(MTRBaseDevice * _Nullable device, NSError * _Nullable error) { |
118 |
| - CHIP_ERROR err = CHIP_NO_ERROR; |
119 |
| - if (error) { |
120 |
| - err = MTRErrorToCHIPErrorCode(error); |
121 |
| - LogNSError("Error: ", error); |
122 |
| - SetCommandExitStatus(err); |
123 |
| - } else if (device == nil) { |
124 |
| - ChipLogError(chipTool, "Error: %s", chip::ErrorStr(CHIP_ERROR_INTERNAL)); |
125 |
| - SetCommandExitStatus(CHIP_ERROR_INTERNAL); |
126 |
| - } else { |
127 |
| - ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId); |
128 |
| - MTRBaseClusterOperationalCredentials * opCredsCluster = |
129 |
| - [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue]; |
130 |
| - [opCredsCluster |
131 |
| - readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) { |
132 |
| - if (readError) { |
133 |
| - CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError); |
134 |
| - LogNSError("Failed to get current fabric: ", readError); |
135 |
| - SetCommandExitStatus(readErr); |
136 |
| - return; |
137 |
| - } |
138 |
| - MTROperationalCredentialsClusterRemoveFabricParams * params = |
139 |
| - [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init]; |
140 |
| - params.fabricIndex = value; |
141 |
| - [opCredsCluster |
142 |
| - removeFabricWithParams:params |
143 |
| - completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data, |
144 |
| - NSError * _Nullable removeError) { |
145 |
| - CHIP_ERROR removeErr = CHIP_NO_ERROR; |
146 |
| - if (removeError) { |
147 |
| - removeErr = MTRErrorToCHIPErrorCode(removeError); |
148 |
| - LogNSError("Failed to remove current fabric: ", removeError); |
149 |
| - } else { |
150 |
| - ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId); |
151 |
| - } |
152 |
| - SetCommandExitStatus(removeErr); |
153 |
| - }]; |
154 |
| - }]; |
155 |
| - } |
156 |
| - }]; |
| 104 | + auto * device = [MTRBaseDevice deviceWithNodeID:@(mNodeId) controller:commissioner]; |
| 105 | + |
| 106 | + ChipLogProgress(chipTool, "Attempting to unpair device %llu", mNodeId); |
| 107 | + MTRBaseClusterOperationalCredentials * opCredsCluster = |
| 108 | + [[MTRBaseClusterOperationalCredentials alloc] initWithDevice:device endpoint:@(0) queue:callbackQueue]; |
| 109 | + [opCredsCluster readAttributeCurrentFabricIndexWithCompletion:^(NSNumber * _Nullable value, NSError * _Nullable readError) { |
| 110 | + if (readError) { |
| 111 | + CHIP_ERROR readErr = MTRErrorToCHIPErrorCode(readError); |
| 112 | + LogNSError("Failed to get current fabric: ", readError); |
| 113 | + SetCommandExitStatus(readErr); |
| 114 | + return; |
| 115 | + } |
| 116 | + MTROperationalCredentialsClusterRemoveFabricParams * params = |
| 117 | + [[MTROperationalCredentialsClusterRemoveFabricParams alloc] init]; |
| 118 | + params.fabricIndex = value; |
| 119 | + [opCredsCluster removeFabricWithParams:params |
| 120 | + completion:^(MTROperationalCredentialsClusterNOCResponseParams * _Nullable data, |
| 121 | + NSError * _Nullable removeError) { |
| 122 | + CHIP_ERROR removeErr = CHIP_NO_ERROR; |
| 123 | + if (removeError) { |
| 124 | + removeErr = MTRErrorToCHIPErrorCode(removeError); |
| 125 | + LogNSError("Failed to remove current fabric: ", removeError); |
| 126 | + } else { |
| 127 | + ChipLogProgress(chipTool, "Successfully unpaired deviceId %llu", mNodeId); |
| 128 | + } |
| 129 | + SetCommandExitStatus(removeErr); |
| 130 | + }]; |
| 131 | + }]; |
157 | 132 | }
|
0 commit comments