forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHIPDeviceEvent.h
540 lines (486 loc) · 14 KB
/
CHIPDeviceEvent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2018 Nest Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* Defines events used by the chip Device Layer to signal actions
* or changes in device state.
*/
#pragma once
#include <stdint.h>
#include <inet/IPAddress.h>
#include <lib/core/DataModelTypes.h>
namespace chip {
namespace DeviceLayer {
namespace DeviceEventType {
enum
{
kFlag_IsPublic = 0x8000,
kFlag_IsPlatformSpecific = 0x4000,
kFlag_Reserved1 = 0x2000,
kFlag_Reserved2 = 0x1000,
kMaxEventNum = 0x0FFF,
};
/**
* Event Type Ranges
*
* Defines numeric ranges for event types based on their visibility to the application,
* an whether or not they are specific to a particular platform adaptation.
*/
enum EventTypeRanges
{
/**
* Public Event Range
*
* Denotes a range of event types that are publicly visible to applications. Events in this
* range a generic to all platforms.
*/
kRange_Public = kFlag_IsPublic,
/**
* Public, Platform-specific Event Range
*
* Denotes a range of platform-specific event types that are publicly visible to applications.
*/
kRange_PublicPlatformSpecific = kFlag_IsPublic | kFlag_IsPlatformSpecific,
/**
* Internal Event Range
*
* Denotes a range of event types that are internal to the chip Device Layer. Events in this
* range a generic to all platforms.
*/
kRange_Internal = 0,
/**
* Internal, Platform-specific Event Range
*
* Denotes a range of platform-specific event types that are internal to the chip Device Layer.
*/
kRange_InternalPlatformSpecific = kFlag_IsPlatformSpecific,
};
inline bool IsPublic(uint16_t eventType)
{
return (eventType & kFlag_IsPublic) != 0;
}
inline bool IsInternal(uint16_t eventType)
{
return (eventType & kFlag_IsPublic) == 0;
}
inline bool IsPlatformSpecific(uint16_t eventType)
{
return (eventType & kFlag_IsPlatformSpecific) != 0;
}
inline bool IsPlatformGeneric(uint16_t eventType)
{
return (eventType & kFlag_IsPlatformSpecific) == 0;
}
/**
* Public Event Types
*
* Enumerates event types that are visible to the application and common across
* all platforms.
*/
enum PublicEventTypes
{
/**
* WiFi Connectivity Change
*
* Signals a change in connectivity of the device's WiFi station interface.
*/
kWiFiConnectivityChange = kRange_Public,
/**
* Thread Connectivity Change
*
* Signals a change in connectivity of the device's Thread interface.
*/
kThreadConnectivityChange,
/**
* Internet Connectivity Change
*
* Signals a change in the device's ability to communicate via the Internet.
*/
kInternetConnectivityChange,
/**
* Service Connectivity Change
*
* Signals a change in the device's ability to communicate with a chip-enabled service.
*/
kServiceConnectivityChange,
/**
* Service Provisioning Change
*
* Signals a change to the device's service provisioning state.
*/
kServiceProvisioningChange,
/**
* Time Sync Change
*
* Signals a change to the device's real time clock synchronization state.
*/
kTimeSyncChange,
/**
* CHIPoBLE Connection Established
*
* Signals that an external entity has established a new CHIPoBLE connection with the device.
*/
kCHIPoBLEConnectionEstablished,
/**
* CHIPoBLE Connection Closed
*
* Signals that an external entity has closed existing CHIPoBLE connection with the device.
*/
kCHIPoBLEConnectionClosed,
/**
* Request BLE connections to be closed.
* This is used in the supportsConcurrentConnection = False case.
*/
kCloseAllBleConnections,
/**
* When supportsConcurrentConnection = False, the ConnectNetwork command cannot start until
* the BLE device is closed and the Operation Network device (e.g. WiFi) has been started.
*/
kWiFiDeviceAvailable,
kOperationalNetworkStarted,
/**
* Thread State Change
*
* Signals that a state change has occurred in the Thread stack.
*/
kThreadStateChange,
/**
* Thread Interface State Change
*
* Signals that the state of the Thread network interface has changed.
*/
kThreadInterfaceStateChange,
/**
* chip-over-BLE (CHIPoBLE) Advertising Change
*
* Signals that the state of CHIPoBLE advertising has changed.
*/
kCHIPoBLEAdvertisingChange,
/**
* IP address availability - either ipv4 or ipv6 addresses assigned to the underlying
* wifi/ethernet interface.
*/
kInterfaceIpAddressChanged,
/**
* Commissioning has completed by a call to the general commissioning cluster command.
*/
kCommissioningComplete,
/**
* Signals that the fail-safe timer expired before the CommissioningComplete command was
* successfully invoked.
*/
kFailSafeTimerExpired,
/**
*
*/
kOperationalNetworkEnabled,
/**
* Signals that DNS-SD has been initialized and is ready to operate.
*/
kDnssdInitialized,
/**
* Signals that DNS-SD backend was restarted and services must be published again.
*/
kDnssdRestartNeeded,
/**
* Signals that bindings were updated.
*/
kBindingsChangedViaCluster,
/**
* Signals that the state of the OTA engine changed.
*/
kOtaStateChanged,
/**
* Server initialization has completed.
*
* Signals that all server components have been initialized and the node is ready to establish
* connections with other nodes. This event can be used to trigger on-boot actions that require
* sending messages to other nodes.
*/
kServerReady,
};
/**
* Internal Event Types
*
* Enumerates event types that are internal to the chip Device Layer, but common across
* all platforms.
*/
enum InternalEventTypes
{
kEventTypeNotSet = kRange_Internal,
kNoOp,
kCallWorkFunct,
kChipLambdaEvent,
kChipSystemLayerEvent,
kCHIPoBLESubscribe,
kCHIPoBLEUnsubscribe,
kCHIPoBLEWriteReceived,
kCHIPoBLEIndicateConfirm,
/**
* Post this event in case of a BLE connection error. This event should be posted
* if the BLE central disconnects without unsubscribing from the BLE characteristic.
* This event should populate CHIPoBLEConnectionError structure.
*/
kCHIPoBLEConnectionError,
kCHIPoBLENotifyConfirm
};
static_assert(kEventTypeNotSet == 0, "kEventTypeNotSet must be defined as 0");
} // namespace DeviceEventType
/**
* Connectivity Change
*
* Describes a change in some aspect of connectivity associated with a chip device.
*/
enum ConnectivityChange
{
kConnectivity_NoChange = 0,
kConnectivity_Established = 1,
kConnectivity_Lost = -1
};
enum class InterfaceIpChangeType
{
kIpV4_Assigned,
kIpV4_Lost,
kIpV6_Assigned,
kIpV6_Lost,
};
/**
* Activity Change
*
* Describes a change in some activity associated with a chip device.
*/
enum ActivityChange
{
kActivity_NoChange = 0,
kActivity_Started = 1,
kActivity_Stopped = -1,
};
enum OtaState
{
kOtaSpaceAvailable = 0,
/**
* This state indicates that Node is currently downloading a software update.
*/
kOtaDownloadInProgress,
/**
* This state indicates that Node has successfully downloaded a software update.
*/
kOtaDownloadComplete,
/**
* This state indicates that Node has failed to download a software update.
*/
kOtaDownloadFailed,
/**
* This state indicates that Node has aborted the download of a software update.
*/
kOtaDownloadAborted,
/**
* This state indicate that Node is currently in the process of verifying and applying a software update.
*/
kOtaApplyInProgress,
/**
* This state indicates that Node has successfully applied a software update.
*/
kOtaApplyComplete,
/**
* This state indicates that Node has failed to apply a software update.
*/
kOtaApplyFailed,
};
inline ConnectivityChange GetConnectivityChange(bool prevState, bool newState)
{
if (prevState == newState)
return kConnectivity_NoChange;
if (newState)
return kConnectivity_Established;
return kConnectivity_Lost;
}
/**
* A pointer to a function that performs work asynchronously.
*/
typedef void (*AsyncWorkFunct)(intptr_t arg);
} // namespace DeviceLayer
} // namespace chip
/* Include a header file containing platform-specific event definitions.
*/
#ifdef EXTERNAL_CHIPDEVICEPLATFORMEVENT_HEADER
#include EXTERNAL_CHIPDEVICEPLATFORMEVENT_HEADER
#elif defined(CHIP_DEVICE_LAYER_TARGET)
#define CHIPDEVICEPLATFORMEVENT_HEADER <platform/CHIP_DEVICE_LAYER_TARGET/CHIPDevicePlatformEvent.h>
#include CHIPDEVICEPLATFORMEVENT_HEADER
#endif // defined(CHIP_DEVICE_LAYER_TARGET)
#include <ble/Ble.h>
#include <inet/InetInterface.h>
#include <lib/support/LambdaBridge.h>
#include <system/SystemEvent.h>
#include <system/SystemLayer.h>
#include <system/SystemPacketBuffer.h>
namespace chip {
namespace DeviceLayer {
/**
* Represents a chip Device Layer event.
*/
struct ChipDeviceEvent final
{
uint16_t Type;
union
{
ChipDevicePlatformEvent Platform;
LambdaBridge LambdaEvent;
struct
{
AsyncWorkFunct WorkFunct;
intptr_t Arg;
} CallWorkFunct;
struct
{
ConnectivityChange Result;
} WiFiConnectivityChange;
struct
{
ConnectivityChange Result;
} ThreadConnectivityChange;
struct
{
ConnectivityChange IPv4;
ConnectivityChange IPv6;
// WARNING: There used to be `char address[INET6_ADDRSTRLEN]` here and it is
// deprecated/removed since it was too large and only used for logging.
// Consider not relying on ipAddress field either since the platform
// layer *does not actually validate* that the actual internet is reachable
// before issuing this event *and* there may be multiple addresses
// (especially IPv6) so it's recommended to use `ChipDevicePlatformEvent`
// instead and do something that is better for your platform.
chip::Inet::IPAddress ipAddress;
} InternetConnectivityChange;
struct
{
struct
{
ConnectivityChange Result;
} Overall;
struct
{
ConnectivityChange Result;
} ViaThread;
} ServiceConnectivityChange;
struct
{
ConnectivityChange Result;
} ServiceSubscriptionStateChange;
struct
{
bool IsMemberOfFabric;
} FabricMembershipChange;
struct
{
bool IsServiceProvisioned;
bool ServiceConfigUpdated;
} ServiceProvisioningChange;
struct
{
bool IsPairedToAccount;
} AccountPairingChange;
struct
{
bool IsTimeSynchronized;
} TimeSyncChange;
struct
{
uint64_t PeerNodeId;
uint16_t SessionKeyId;
uint8_t SessionType;
bool IsCommissioner;
} SessionEstablished;
struct
{
BLE_CONNECTION_OBJECT ConId;
} CHIPoBLESubscribe;
struct
{
BLE_CONNECTION_OBJECT ConId;
} CHIPoBLEUnsubscribe;
struct
{
BLE_CONNECTION_OBJECT ConId;
chip::System::PacketBuffer * Data;
} CHIPoBLEWriteReceived;
struct
{
BLE_CONNECTION_OBJECT ConId;
} CHIPoBLEIndicateConfirm;
struct
{
BLE_CONNECTION_OBJECT ConId;
CHIP_ERROR Reason;
} CHIPoBLEConnectionError;
struct
{
BLE_CONNECTION_OBJECT ConId;
} CHIPoBLENotifyConfirm;
struct
{
bool RoleChanged : 1;
bool AddressChanged : 1;
bool NetDataChanged : 1;
bool ChildNodesChanged : 1;
struct
{
uint32_t Flags;
} OpenThread;
} ThreadStateChange;
struct
{
ActivityChange Result;
} CHIPoBLEAdvertisingChange;
struct
{
InterfaceIpChangeType Type;
} InterfaceIpAddressChanged;
struct
{
uint64_t nodeId;
FabricIndex fabricIndex;
} CommissioningComplete;
struct
{
FabricIndex fabricIndex;
} BindingsChanged;
struct
{
FabricIndex fabricIndex;
bool addNocCommandHasBeenInvoked;
bool updateNocCommandHasBeenInvoked;
} FailSafeTimerExpired;
struct
{
// TODO(cecille): This should just specify wifi or thread since we assume at most 1.
int network;
} OperationalNetwork;
struct
{
OtaState newState;
} OtaStateChanged;
};
bool IsPublic() const { return DeviceEventType::IsPublic(Type); }
bool IsInternal() const { return DeviceEventType::IsInternal(Type); }
bool IsPlatformSpecific() const { return DeviceEventType::IsPlatformSpecific(Type); }
bool IsPlatformGeneric() const { return DeviceEventType::IsPlatformGeneric(Type); }
};
} // namespace DeviceLayer
} // namespace chip