1*cfb92d14SAndroid Build Coastguard Worker#!/usr/bin/env python3 2*cfb92d14SAndroid Build Coastguard Worker# 3*cfb92d14SAndroid Build Coastguard Worker# Copyright (c) 2019, The OpenThread Authors. 4*cfb92d14SAndroid Build Coastguard Worker# All rights reserved. 5*cfb92d14SAndroid Build Coastguard Worker# 6*cfb92d14SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without 7*cfb92d14SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met: 8*cfb92d14SAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright 9*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer. 10*cfb92d14SAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright 11*cfb92d14SAndroid Build Coastguard Worker# notice, this list of conditions and the following disclaimer in the 12*cfb92d14SAndroid Build Coastguard Worker# documentation and/or other materials provided with the distribution. 13*cfb92d14SAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the 14*cfb92d14SAndroid Build Coastguard Worker# names of its contributors may be used to endorse or promote products 15*cfb92d14SAndroid Build Coastguard Worker# derived from this software without specific prior written permission. 16*cfb92d14SAndroid Build Coastguard Worker# 17*cfb92d14SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18*cfb92d14SAndroid Build Coastguard Worker# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*cfb92d14SAndroid Build Coastguard Worker# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*cfb92d14SAndroid Build Coastguard Worker# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21*cfb92d14SAndroid Build Coastguard Worker# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*cfb92d14SAndroid Build Coastguard Worker# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*cfb92d14SAndroid Build Coastguard Worker# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*cfb92d14SAndroid Build Coastguard Worker# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*cfb92d14SAndroid Build Coastguard Worker# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*cfb92d14SAndroid Build Coastguard Worker# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*cfb92d14SAndroid Build Coastguard Worker# POSSIBILITY OF SUCH DAMAGE. 28*cfb92d14SAndroid Build Coastguard Worker# 29*cfb92d14SAndroid Build Coastguard Worker 30*cfb92d14SAndroid Build Coastguard Workerfrom binascii import hexlify 31*cfb92d14SAndroid Build Coastguard Workerfrom enum import IntEnum 32*cfb92d14SAndroid Build Coastguard Workerimport io 33*cfb92d14SAndroid Build Coastguard Workerimport logging 34*cfb92d14SAndroid Build Coastguard Workerimport struct 35*cfb92d14SAndroid Build Coastguard Worker 36*cfb92d14SAndroid Build Coastguard Workerfrom network_data import SubTlvsFactory 37*cfb92d14SAndroid Build Coastguard Workerfrom tlvs_parsing import UnknownTlvFactory 38*cfb92d14SAndroid Build Coastguard Workerimport common 39*cfb92d14SAndroid Build Coastguard Worker 40*cfb92d14SAndroid Build Coastguard Worker 41*cfb92d14SAndroid Build Coastguard Workerclass TlvType(IntEnum): 42*cfb92d14SAndroid Build Coastguard Worker CHANNEL = 0 43*cfb92d14SAndroid Build Coastguard Worker PAN_ID = 1 44*cfb92d14SAndroid Build Coastguard Worker EXTENDED_PANID = 2 45*cfb92d14SAndroid Build Coastguard Worker NETWORK_NAME = 3 46*cfb92d14SAndroid Build Coastguard Worker PSKC = 4 47*cfb92d14SAndroid Build Coastguard Worker NETWORK_KEY = 5 48*cfb92d14SAndroid Build Coastguard Worker NETWORK_KEY_SEQUENCE_COUNTER = 6 49*cfb92d14SAndroid Build Coastguard Worker NETWORK_MESH_LOCAL_PREFIX = 7 50*cfb92d14SAndroid Build Coastguard Worker STEERING_DATA = 8 51*cfb92d14SAndroid Build Coastguard Worker BORDER_AGENT_LOCATOR = 9 52*cfb92d14SAndroid Build Coastguard Worker COMMISSIONER_ID = 10 53*cfb92d14SAndroid Build Coastguard Worker COMMISSIONER_SESSION_ID = 11 54*cfb92d14SAndroid Build Coastguard Worker SECURITY_POLICY = 12 55*cfb92d14SAndroid Build Coastguard Worker GET = 13 56*cfb92d14SAndroid Build Coastguard Worker ACTIVE_TIMESTAMP = 14 57*cfb92d14SAndroid Build Coastguard Worker COMMISSIONER_UDP_PORT = 15 58*cfb92d14SAndroid Build Coastguard Worker STATE = 16 59*cfb92d14SAndroid Build Coastguard Worker JOINER_DTLS_ENCAPSULATION = 17 60*cfb92d14SAndroid Build Coastguard Worker JOINER_UDP_PORT = 18 61*cfb92d14SAndroid Build Coastguard Worker JOINER_IID = 19 62*cfb92d14SAndroid Build Coastguard Worker JOINER_ROUTER_LOCATOR = 20 63*cfb92d14SAndroid Build Coastguard Worker JOINER_ROUTER_KEK = 21 64*cfb92d14SAndroid Build Coastguard Worker PROVISIONING_URL = 32 65*cfb92d14SAndroid Build Coastguard Worker VENDOR_NAME = 33 66*cfb92d14SAndroid Build Coastguard Worker VENDOR_MODEL = 34 67*cfb92d14SAndroid Build Coastguard Worker VENDOR_SW_VERSION = 35 68*cfb92d14SAndroid Build Coastguard Worker VENDOR_DATA = 36 69*cfb92d14SAndroid Build Coastguard Worker VENDOR_STACK_VERSION = 37 70*cfb92d14SAndroid Build Coastguard Worker UDP_ENCAPSULATION = 48 71*cfb92d14SAndroid Build Coastguard Worker IPV6_ADDRESS = 49 72*cfb92d14SAndroid Build Coastguard Worker PENDING_TIMESTAMP = 51 73*cfb92d14SAndroid Build Coastguard Worker DELAY_TIMER = 52 74*cfb92d14SAndroid Build Coastguard Worker CHANNEL_MASK = 53 75*cfb92d14SAndroid Build Coastguard Worker COUNT = 54 76*cfb92d14SAndroid Build Coastguard Worker PERIOD = 55 77*cfb92d14SAndroid Build Coastguard Worker SCAN_DURATION = 56 78*cfb92d14SAndroid Build Coastguard Worker ENERGY_LIST = 57 79*cfb92d14SAndroid Build Coastguard Worker CSL_SYNCHRONIZED_TIMEOUT = 85 80*cfb92d14SAndroid Build Coastguard Worker CSL_CLOCK_ACCURACY = 86 81*cfb92d14SAndroid Build Coastguard Worker DISCOVERY_REQUEST = 128 82*cfb92d14SAndroid Build Coastguard Worker DISCOVERY_RESPONSE = 129 83*cfb92d14SAndroid Build Coastguard Worker 84*cfb92d14SAndroid Build Coastguard Worker 85*cfb92d14SAndroid Build Coastguard Workerclass MeshCopState(IntEnum): 86*cfb92d14SAndroid Build Coastguard Worker ACCEPT = 0x1 87*cfb92d14SAndroid Build Coastguard Worker REJECT = 0xff 88*cfb92d14SAndroid Build Coastguard Worker 89*cfb92d14SAndroid Build Coastguard Worker 90*cfb92d14SAndroid Build Coastguard Workerclass MeshCopMessageType(IntEnum): 91*cfb92d14SAndroid Build Coastguard Worker JOIN_FIN_REQ = (1,) 92*cfb92d14SAndroid Build Coastguard Worker JOIN_FIN_RSP = (2,) 93*cfb92d14SAndroid Build Coastguard Worker JOIN_ENT_NTF = (3,) 94*cfb92d14SAndroid Build Coastguard Worker JOIN_ENT_RSP = 4 95*cfb92d14SAndroid Build Coastguard Worker 96*cfb92d14SAndroid Build Coastguard Worker 97*cfb92d14SAndroid Build Coastguard Workerdef create_mesh_cop_message_type_set(): 98*cfb92d14SAndroid Build Coastguard Worker return [ 99*cfb92d14SAndroid Build Coastguard Worker MeshCopMessageType.JOIN_FIN_REQ, 100*cfb92d14SAndroid Build Coastguard Worker MeshCopMessageType.JOIN_FIN_RSP, 101*cfb92d14SAndroid Build Coastguard Worker MeshCopMessageType.JOIN_ENT_NTF, 102*cfb92d14SAndroid Build Coastguard Worker MeshCopMessageType.JOIN_ENT_RSP, 103*cfb92d14SAndroid Build Coastguard Worker ] 104*cfb92d14SAndroid Build Coastguard Worker 105*cfb92d14SAndroid Build Coastguard Worker 106*cfb92d14SAndroid Build Coastguard Worker# Channel TLV (0) 107*cfb92d14SAndroid Build Coastguard Workerclass Channel(object): 108*cfb92d14SAndroid Build Coastguard Worker 109*cfb92d14SAndroid Build Coastguard Worker def __init__(self, channel_page, channel): 110*cfb92d14SAndroid Build Coastguard Worker self._channel_page = channel_page 111*cfb92d14SAndroid Build Coastguard Worker self._channel = channel 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Worker @property 114*cfb92d14SAndroid Build Coastguard Worker def channel_page(self): 115*cfb92d14SAndroid Build Coastguard Worker return self._channel_page 116*cfb92d14SAndroid Build Coastguard Worker 117*cfb92d14SAndroid Build Coastguard Worker @property 118*cfb92d14SAndroid Build Coastguard Worker def channel(self): 119*cfb92d14SAndroid Build Coastguard Worker return self._channel 120*cfb92d14SAndroid Build Coastguard Worker 121*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 122*cfb92d14SAndroid Build Coastguard Worker common.expect_the_same_class(self, other) 123*cfb92d14SAndroid Build Coastguard Worker 124*cfb92d14SAndroid Build Coastguard Worker return (self._channel_page == other._channel_page and self._channel == other.__channel) 125*cfb92d14SAndroid Build Coastguard Worker 126*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 127*cfb92d14SAndroid Build Coastguard Worker return 'Channel(channel_page={},channel={})'.format(self._channel_page, self._channel) 128*cfb92d14SAndroid Build Coastguard Worker 129*cfb92d14SAndroid Build Coastguard Worker def to_hex(self): 130*cfb92d14SAndroid Build Coastguard Worker return struct.pack('>BBBH', TlvType.CHANNEL, 3, self.channel_page, self.channel) 131*cfb92d14SAndroid Build Coastguard Worker 132*cfb92d14SAndroid Build Coastguard Worker 133*cfb92d14SAndroid Build Coastguard Workerclass ChannelFactory(object): 134*cfb92d14SAndroid Build Coastguard Worker 135*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 136*cfb92d14SAndroid Build Coastguard Worker data_tp = struct.unpack('>BH', data.read(3)) 137*cfb92d14SAndroid Build Coastguard Worker channel_page = data_tp[0] 138*cfb92d14SAndroid Build Coastguard Worker channel = data_tp[1] 139*cfb92d14SAndroid Build Coastguard Worker return Channel(channel_page, channel) 140*cfb92d14SAndroid Build Coastguard Worker 141*cfb92d14SAndroid Build Coastguard Worker 142*cfb92d14SAndroid Build Coastguard Worker# PanId TLV (1) 143*cfb92d14SAndroid Build Coastguard Workerclass Panid(object): 144*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 145*cfb92d14SAndroid Build Coastguard Worker pass 146*cfb92d14SAndroid Build Coastguard Worker 147*cfb92d14SAndroid Build Coastguard Worker 148*cfb92d14SAndroid Build Coastguard Workerclass PanidFactory(object): 149*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 150*cfb92d14SAndroid Build Coastguard Worker 151*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 152*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 153*cfb92d14SAndroid Build Coastguard Worker 154*cfb92d14SAndroid Build Coastguard Worker 155*cfb92d14SAndroid Build Coastguard Worker# ExtendedPanid TLV (2) 156*cfb92d14SAndroid Build Coastguard Workerclass ExtendedPanid(object): 157*cfb92d14SAndroid Build Coastguard Worker 158*cfb92d14SAndroid Build Coastguard Worker def __init__(self, extended_panid): 159*cfb92d14SAndroid Build Coastguard Worker self._extended_panid = extended_panid 160*cfb92d14SAndroid Build Coastguard Worker 161*cfb92d14SAndroid Build Coastguard Worker @property 162*cfb92d14SAndroid Build Coastguard Worker def extended_panid(self): 163*cfb92d14SAndroid Build Coastguard Worker return self._extended_panid 164*cfb92d14SAndroid Build Coastguard Worker 165*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 166*cfb92d14SAndroid Build Coastguard Worker return (isinstance(self, type(other)) and self.extended_panid == other.extended_panid) 167*cfb92d14SAndroid Build Coastguard Worker 168*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 169*cfb92d14SAndroid Build Coastguard Worker return "ExtendedPanid(extended_panid={})".format(self.extended_panid) 170*cfb92d14SAndroid Build Coastguard Worker 171*cfb92d14SAndroid Build Coastguard Worker 172*cfb92d14SAndroid Build Coastguard Workerclass ExtendedPanidFactory(object): 173*cfb92d14SAndroid Build Coastguard Worker 174*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 175*cfb92d14SAndroid Build Coastguard Worker extended_panid = struct.unpack(">Q", data.read(8))[0] 176*cfb92d14SAndroid Build Coastguard Worker return ExtendedPanid(extended_panid) 177*cfb92d14SAndroid Build Coastguard Worker 178*cfb92d14SAndroid Build Coastguard Worker 179*cfb92d14SAndroid Build Coastguard Worker# NetworkName TLV (3) 180*cfb92d14SAndroid Build Coastguard Workerclass NetworkName(object): 181*cfb92d14SAndroid Build Coastguard Worker 182*cfb92d14SAndroid Build Coastguard Worker def __init__(self, network_name): 183*cfb92d14SAndroid Build Coastguard Worker self._network_name = network_name 184*cfb92d14SAndroid Build Coastguard Worker 185*cfb92d14SAndroid Build Coastguard Worker @property 186*cfb92d14SAndroid Build Coastguard Worker def network_name(self): 187*cfb92d14SAndroid Build Coastguard Worker return self._network_name 188*cfb92d14SAndroid Build Coastguard Worker 189*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 190*cfb92d14SAndroid Build Coastguard Worker return (isinstance(self, type(other)) and self.network_name == other.network_name) 191*cfb92d14SAndroid Build Coastguard Worker 192*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 193*cfb92d14SAndroid Build Coastguard Worker return "NetworkName(network_name={})".format(self.network_name) 194*cfb92d14SAndroid Build Coastguard Worker 195*cfb92d14SAndroid Build Coastguard Worker 196*cfb92d14SAndroid Build Coastguard Workerclass NetworkNameFactory(object): 197*cfb92d14SAndroid Build Coastguard Worker 198*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 199*cfb92d14SAndroid Build Coastguard Worker len = message_info.length 200*cfb92d14SAndroid Build Coastguard Worker network_name = struct.unpack("{}s".format(10), data.read(len))[0] 201*cfb92d14SAndroid Build Coastguard Worker return NetworkName(network_name) 202*cfb92d14SAndroid Build Coastguard Worker 203*cfb92d14SAndroid Build Coastguard Worker 204*cfb92d14SAndroid Build Coastguard Worker# PSKc TLV (4) 205*cfb92d14SAndroid Build Coastguard Workerclass PSKc(object): 206*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 207*cfb92d14SAndroid Build Coastguard Worker pass 208*cfb92d14SAndroid Build Coastguard Worker 209*cfb92d14SAndroid Build Coastguard Worker 210*cfb92d14SAndroid Build Coastguard Workerclass PSKcFactory(object): 211*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 212*cfb92d14SAndroid Build Coastguard Worker 213*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 214*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 215*cfb92d14SAndroid Build Coastguard Worker 216*cfb92d14SAndroid Build Coastguard Worker 217*cfb92d14SAndroid Build Coastguard Worker# NetworkKey TLV (5) 218*cfb92d14SAndroid Build Coastguard Workerclass NetworkKey(object): 219*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 220*cfb92d14SAndroid Build Coastguard Worker pass 221*cfb92d14SAndroid Build Coastguard Worker 222*cfb92d14SAndroid Build Coastguard Worker 223*cfb92d14SAndroid Build Coastguard Workerclass NetworkKeyFactory(object): 224*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 225*cfb92d14SAndroid Build Coastguard Worker 226*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 227*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 228*cfb92d14SAndroid Build Coastguard Worker 229*cfb92d14SAndroid Build Coastguard Worker 230*cfb92d14SAndroid Build Coastguard Worker# NetworkKeySequenceCounter TLV (6) 231*cfb92d14SAndroid Build Coastguard Workerclass NetworkKeySequenceCounter(object): 232*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 233*cfb92d14SAndroid Build Coastguard Worker pass 234*cfb92d14SAndroid Build Coastguard Worker 235*cfb92d14SAndroid Build Coastguard Worker 236*cfb92d14SAndroid Build Coastguard Workerclass NetworkKeySequenceCounterFactory(object): 237*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 238*cfb92d14SAndroid Build Coastguard Worker 239*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 240*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 241*cfb92d14SAndroid Build Coastguard Worker 242*cfb92d14SAndroid Build Coastguard Worker 243*cfb92d14SAndroid Build Coastguard Worker# NetworkMeshLocalPrefix TLV (7) 244*cfb92d14SAndroid Build Coastguard Workerclass NetworkMeshLocalPrefix(object): 245*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 246*cfb92d14SAndroid Build Coastguard Worker pass 247*cfb92d14SAndroid Build Coastguard Worker 248*cfb92d14SAndroid Build Coastguard Worker 249*cfb92d14SAndroid Build Coastguard Workerclass NetworkMeshLocalPrefixFactory(object): 250*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 251*cfb92d14SAndroid Build Coastguard Worker 252*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 253*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 254*cfb92d14SAndroid Build Coastguard Worker 255*cfb92d14SAndroid Build Coastguard Worker 256*cfb92d14SAndroid Build Coastguard Worker# Steering Data TLV (8) 257*cfb92d14SAndroid Build Coastguard Workerclass SteeringData(object): 258*cfb92d14SAndroid Build Coastguard Worker 259*cfb92d14SAndroid Build Coastguard Worker def __init__(self, bloom_filter): 260*cfb92d14SAndroid Build Coastguard Worker self._bloom_filter = bloom_filter 261*cfb92d14SAndroid Build Coastguard Worker 262*cfb92d14SAndroid Build Coastguard Worker @property 263*cfb92d14SAndroid Build Coastguard Worker def bloom_filter(self): 264*cfb92d14SAndroid Build Coastguard Worker return self._bloom_filter 265*cfb92d14SAndroid Build Coastguard Worker 266*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 267*cfb92d14SAndroid Build Coastguard Worker common.expect_the_same_class(self, other) 268*cfb92d14SAndroid Build Coastguard Worker 269*cfb92d14SAndroid Build Coastguard Worker return self._bloom_filter == other._bloom_filter 270*cfb92d14SAndroid Build Coastguard Worker 271*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 272*cfb92d14SAndroid Build Coastguard Worker return "SteeringData(bloom_filter={})".format(hexlify(self._bloom_filter)) 273*cfb92d14SAndroid Build Coastguard Worker 274*cfb92d14SAndroid Build Coastguard Worker def to_hex(self): 275*cfb92d14SAndroid Build Coastguard Worker bloom_filter_len = len(self.bloom_filter) 276*cfb92d14SAndroid Build Coastguard Worker return (struct.pack('>BB', TlvType.STEERING_DATA, bloom_filter_len) + self.bloom_filter) 277*cfb92d14SAndroid Build Coastguard Worker 278*cfb92d14SAndroid Build Coastguard Worker 279*cfb92d14SAndroid Build Coastguard Workerclass SteeringDataFactory: 280*cfb92d14SAndroid Build Coastguard Worker 281*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 282*cfb92d14SAndroid Build Coastguard Worker bloom_filter = data.read(message_info.length) 283*cfb92d14SAndroid Build Coastguard Worker return SteeringData(bloom_filter) 284*cfb92d14SAndroid Build Coastguard Worker 285*cfb92d14SAndroid Build Coastguard Worker 286*cfb92d14SAndroid Build Coastguard Worker# Border Agent Locator TLV (9) 287*cfb92d14SAndroid Build Coastguard Workerclass BorderAgentLocator(object): 288*cfb92d14SAndroid Build Coastguard Worker 289*cfb92d14SAndroid Build Coastguard Worker def __init__(self, address): 290*cfb92d14SAndroid Build Coastguard Worker self._border_agent_locator = address 291*cfb92d14SAndroid Build Coastguard Worker 292*cfb92d14SAndroid Build Coastguard Worker @property 293*cfb92d14SAndroid Build Coastguard Worker def border_agent_locator(self): 294*cfb92d14SAndroid Build Coastguard Worker return self._border_agent_locator 295*cfb92d14SAndroid Build Coastguard Worker 296*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 297*cfb92d14SAndroid Build Coastguard Worker common.expect_the_same_class(self, other) 298*cfb92d14SAndroid Build Coastguard Worker 299*cfb92d14SAndroid Build Coastguard Worker return self._border_agent_locator == other._border_agent_locator 300*cfb92d14SAndroid Build Coastguard Worker 301*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 302*cfb92d14SAndroid Build Coastguard Worker return "BorderAgentLocator(rloc16={})".format(hex(self._border_agent_locator)) 303*cfb92d14SAndroid Build Coastguard Worker 304*cfb92d14SAndroid Build Coastguard Worker def to_hex(self): 305*cfb92d14SAndroid Build Coastguard Worker return struct.pack('>BBH', TlvType.BORDER_AGENT_LOCATOR, 2, self.border_agent_locator) 306*cfb92d14SAndroid Build Coastguard Worker 307*cfb92d14SAndroid Build Coastguard Worker 308*cfb92d14SAndroid Build Coastguard Workerclass BorderAgentLocatorFactory: 309*cfb92d14SAndroid Build Coastguard Worker 310*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 311*cfb92d14SAndroid Build Coastguard Worker border_agent_locator = struct.unpack(">H", data.read(2))[0] 312*cfb92d14SAndroid Build Coastguard Worker return BorderAgentLocator(border_agent_locator) 313*cfb92d14SAndroid Build Coastguard Worker 314*cfb92d14SAndroid Build Coastguard Worker 315*cfb92d14SAndroid Build Coastguard Worker# CommissionerId TLV (10) 316*cfb92d14SAndroid Build Coastguard Workerclass CommissionerId(object): 317*cfb92d14SAndroid Build Coastguard Worker 318*cfb92d14SAndroid Build Coastguard Worker def __init__(self, commissioner_id): 319*cfb92d14SAndroid Build Coastguard Worker self._commissioner_id = commissioner_id 320*cfb92d14SAndroid Build Coastguard Worker 321*cfb92d14SAndroid Build Coastguard Worker @property 322*cfb92d14SAndroid Build Coastguard Worker def commissioner_id(self): 323*cfb92d14SAndroid Build Coastguard Worker return self._commissioner_id 324*cfb92d14SAndroid Build Coastguard Worker 325*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 326*cfb92d14SAndroid Build Coastguard Worker return self.commissioner_id == other.commissioner_id 327*cfb92d14SAndroid Build Coastguard Worker 328*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 329*cfb92d14SAndroid Build Coastguard Worker return "CommissionerId(commissioner_id={})".format(self.commissioner_id) 330*cfb92d14SAndroid Build Coastguard Worker 331*cfb92d14SAndroid Build Coastguard Worker 332*cfb92d14SAndroid Build Coastguard Workerclass CommissionerIdFactory(object): 333*cfb92d14SAndroid Build Coastguard Worker 334*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 335*cfb92d14SAndroid Build Coastguard Worker commissioner_id = data.getvalue().decode('utf-8') 336*cfb92d14SAndroid Build Coastguard Worker return CommissionerId(commissioner_id) 337*cfb92d14SAndroid Build Coastguard Worker 338*cfb92d14SAndroid Build Coastguard Worker 339*cfb92d14SAndroid Build Coastguard Worker# Commissioner Session ID TLV (11) 340*cfb92d14SAndroid Build Coastguard Workerclass CommissionerSessionId(object): 341*cfb92d14SAndroid Build Coastguard Worker 342*cfb92d14SAndroid Build Coastguard Worker def __init__(self, commissioner_session_id): 343*cfb92d14SAndroid Build Coastguard Worker self._commissioner_session_id = commissioner_session_id 344*cfb92d14SAndroid Build Coastguard Worker 345*cfb92d14SAndroid Build Coastguard Worker @property 346*cfb92d14SAndroid Build Coastguard Worker def commissioner_session_id(self): 347*cfb92d14SAndroid Build Coastguard Worker return self._commissioner_session_id 348*cfb92d14SAndroid Build Coastguard Worker 349*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 350*cfb92d14SAndroid Build Coastguard Worker common.expect_the_same_class(self, other) 351*cfb92d14SAndroid Build Coastguard Worker 352*cfb92d14SAndroid Build Coastguard Worker return self._commissioner_session_id == other._commissioner_session_id 353*cfb92d14SAndroid Build Coastguard Worker 354*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 355*cfb92d14SAndroid Build Coastguard Worker return "CommissionerSessionId(commissioner_session_id={})".format(self._commissioner_session_id) 356*cfb92d14SAndroid Build Coastguard Worker 357*cfb92d14SAndroid Build Coastguard Worker def to_hex(self): 358*cfb92d14SAndroid Build Coastguard Worker return struct.pack( 359*cfb92d14SAndroid Build Coastguard Worker '>BBH', 360*cfb92d14SAndroid Build Coastguard Worker TlvType.COMMISSIONER_SESSION_ID, 361*cfb92d14SAndroid Build Coastguard Worker 2, 362*cfb92d14SAndroid Build Coastguard Worker self.commissioner_session_id, 363*cfb92d14SAndroid Build Coastguard Worker ) 364*cfb92d14SAndroid Build Coastguard Worker 365*cfb92d14SAndroid Build Coastguard Worker 366*cfb92d14SAndroid Build Coastguard Workerclass CommissionerSessionIdFactory: 367*cfb92d14SAndroid Build Coastguard Worker 368*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 369*cfb92d14SAndroid Build Coastguard Worker session_id = struct.unpack(">H", data.read(2))[0] 370*cfb92d14SAndroid Build Coastguard Worker return CommissionerSessionId(session_id) 371*cfb92d14SAndroid Build Coastguard Worker 372*cfb92d14SAndroid Build Coastguard Worker 373*cfb92d14SAndroid Build Coastguard Worker# SecurityPolicy TLV (12) 374*cfb92d14SAndroid Build Coastguard Workerclass SecurityPolicy(object): 375*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 376*cfb92d14SAndroid Build Coastguard Worker pass 377*cfb92d14SAndroid Build Coastguard Worker 378*cfb92d14SAndroid Build Coastguard Worker 379*cfb92d14SAndroid Build Coastguard Workerclass SecurityPolicyFactory(object): 380*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 381*cfb92d14SAndroid Build Coastguard Worker 382*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 383*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 384*cfb92d14SAndroid Build Coastguard Worker 385*cfb92d14SAndroid Build Coastguard Worker 386*cfb92d14SAndroid Build Coastguard Worker# Get TLV (13) 387*cfb92d14SAndroid Build Coastguard Workerclass Get(object): 388*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 389*cfb92d14SAndroid Build Coastguard Worker pass 390*cfb92d14SAndroid Build Coastguard Worker 391*cfb92d14SAndroid Build Coastguard Worker 392*cfb92d14SAndroid Build Coastguard Workerclass GetFactory(object): 393*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 394*cfb92d14SAndroid Build Coastguard Worker 395*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 396*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 397*cfb92d14SAndroid Build Coastguard Worker 398*cfb92d14SAndroid Build Coastguard Worker 399*cfb92d14SAndroid Build Coastguard Worker# ActiveTimestamp TLV (14) 400*cfb92d14SAndroid Build Coastguard Workerclass ActiveTimestamp(object): 401*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 402*cfb92d14SAndroid Build Coastguard Worker pass 403*cfb92d14SAndroid Build Coastguard Worker 404*cfb92d14SAndroid Build Coastguard Worker 405*cfb92d14SAndroid Build Coastguard Workerclass ActiveTimestampFactory(object): 406*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 407*cfb92d14SAndroid Build Coastguard Worker 408*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 409*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 410*cfb92d14SAndroid Build Coastguard Worker 411*cfb92d14SAndroid Build Coastguard Worker 412*cfb92d14SAndroid Build Coastguard Worker# Commissioner UDP Port TLV (15) 413*cfb92d14SAndroid Build Coastguard Workerclass CommissionerUdpPort(object): 414*cfb92d14SAndroid Build Coastguard Worker 415*cfb92d14SAndroid Build Coastguard Worker def __init__(self, udp_port): 416*cfb92d14SAndroid Build Coastguard Worker self._udp_port = udp_port 417*cfb92d14SAndroid Build Coastguard Worker 418*cfb92d14SAndroid Build Coastguard Worker @property 419*cfb92d14SAndroid Build Coastguard Worker def udp_port(self): 420*cfb92d14SAndroid Build Coastguard Worker return self._udp_port 421*cfb92d14SAndroid Build Coastguard Worker 422*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 423*cfb92d14SAndroid Build Coastguard Worker common.expect_the_same_class(self, other) 424*cfb92d14SAndroid Build Coastguard Worker 425*cfb92d14SAndroid Build Coastguard Worker return self._udp_port == other._udp_port 426*cfb92d14SAndroid Build Coastguard Worker 427*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 428*cfb92d14SAndroid Build Coastguard Worker return "CommissionerUdpPort(udp_port={})".format(self._udp_port) 429*cfb92d14SAndroid Build Coastguard Worker 430*cfb92d14SAndroid Build Coastguard Worker 431*cfb92d14SAndroid Build Coastguard Workerclass CommissionerUdpPortFactory: 432*cfb92d14SAndroid Build Coastguard Worker 433*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 434*cfb92d14SAndroid Build Coastguard Worker udp_port = struct.unpack(">H", data.read(2))[0] 435*cfb92d14SAndroid Build Coastguard Worker return CommissionerUdpPort(udp_port) 436*cfb92d14SAndroid Build Coastguard Worker 437*cfb92d14SAndroid Build Coastguard Worker 438*cfb92d14SAndroid Build Coastguard Worker# State TLV (16) 439*cfb92d14SAndroid Build Coastguard Workerclass State(object): 440*cfb92d14SAndroid Build Coastguard Worker 441*cfb92d14SAndroid Build Coastguard Worker def __init__(self, state): 442*cfb92d14SAndroid Build Coastguard Worker self._state = state 443*cfb92d14SAndroid Build Coastguard Worker 444*cfb92d14SAndroid Build Coastguard Worker @property 445*cfb92d14SAndroid Build Coastguard Worker def state(self): 446*cfb92d14SAndroid Build Coastguard Worker return self._state 447*cfb92d14SAndroid Build Coastguard Worker 448*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 449*cfb92d14SAndroid Build Coastguard Worker return self.state == other.state 450*cfb92d14SAndroid Build Coastguard Worker 451*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 452*cfb92d14SAndroid Build Coastguard Worker return "State(state={})".format(self.state) 453*cfb92d14SAndroid Build Coastguard Worker 454*cfb92d14SAndroid Build Coastguard Worker 455*cfb92d14SAndroid Build Coastguard Workerclass StateFactory: 456*cfb92d14SAndroid Build Coastguard Worker 457*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 458*cfb92d14SAndroid Build Coastguard Worker state = ord(data.read(1)) 459*cfb92d14SAndroid Build Coastguard Worker return State(state) 460*cfb92d14SAndroid Build Coastguard Worker 461*cfb92d14SAndroid Build Coastguard Worker 462*cfb92d14SAndroid Build Coastguard Worker# JoinerDtlsEncapsulation TLV (17) 463*cfb92d14SAndroid Build Coastguard Workerclass JoinerDtlsEncapsulation(object): 464*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 465*cfb92d14SAndroid Build Coastguard Worker pass 466*cfb92d14SAndroid Build Coastguard Worker 467*cfb92d14SAndroid Build Coastguard Worker 468*cfb92d14SAndroid Build Coastguard Workerclass JoinerDtlsEncapsulationFactory(object): 469*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 470*cfb92d14SAndroid Build Coastguard Worker 471*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 472*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 473*cfb92d14SAndroid Build Coastguard Worker 474*cfb92d14SAndroid Build Coastguard Worker 475*cfb92d14SAndroid Build Coastguard Worker# JoinerUdpPort TLV (18) 476*cfb92d14SAndroid Build Coastguard Workerclass JoinerUdpPort(object): 477*cfb92d14SAndroid Build Coastguard Worker 478*cfb92d14SAndroid Build Coastguard Worker def __init__(self, udp_port): 479*cfb92d14SAndroid Build Coastguard Worker self._udp_port = udp_port 480*cfb92d14SAndroid Build Coastguard Worker 481*cfb92d14SAndroid Build Coastguard Worker @property 482*cfb92d14SAndroid Build Coastguard Worker def udp_port(self): 483*cfb92d14SAndroid Build Coastguard Worker return self._udp_port 484*cfb92d14SAndroid Build Coastguard Worker 485*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 486*cfb92d14SAndroid Build Coastguard Worker return (isinstance(self, type(other)) and self.udp_port == other.udp_port) 487*cfb92d14SAndroid Build Coastguard Worker 488*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 489*cfb92d14SAndroid Build Coastguard Worker return "JoinerUdpPort(udp_port={})".format(self.udp_port) 490*cfb92d14SAndroid Build Coastguard Worker 491*cfb92d14SAndroid Build Coastguard Worker 492*cfb92d14SAndroid Build Coastguard Workerclass JoinerUdpPortFactory(object): 493*cfb92d14SAndroid Build Coastguard Worker 494*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 495*cfb92d14SAndroid Build Coastguard Worker udp_port = struct.unpack(">H", data.read(2))[0] 496*cfb92d14SAndroid Build Coastguard Worker return JoinerUdpPort(udp_port) 497*cfb92d14SAndroid Build Coastguard Worker 498*cfb92d14SAndroid Build Coastguard Worker 499*cfb92d14SAndroid Build Coastguard Worker# JoinerIID TLV (19) 500*cfb92d14SAndroid Build Coastguard Workerclass JoinerIID(object): 501*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 502*cfb92d14SAndroid Build Coastguard Worker pass 503*cfb92d14SAndroid Build Coastguard Worker 504*cfb92d14SAndroid Build Coastguard Worker 505*cfb92d14SAndroid Build Coastguard Workerclass JoinerIIDFactory(object): 506*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 507*cfb92d14SAndroid Build Coastguard Worker 508*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 509*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 510*cfb92d14SAndroid Build Coastguard Worker 511*cfb92d14SAndroid Build Coastguard Worker 512*cfb92d14SAndroid Build Coastguard Worker# JoinerRouterLocator TLV (20) 513*cfb92d14SAndroid Build Coastguard Workerclass JoinerRouterLocator(object): 514*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 515*cfb92d14SAndroid Build Coastguard Worker pass 516*cfb92d14SAndroid Build Coastguard Worker 517*cfb92d14SAndroid Build Coastguard Worker 518*cfb92d14SAndroid Build Coastguard Workerclass JoinerRouterLocatorFactory(object): 519*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 520*cfb92d14SAndroid Build Coastguard Worker 521*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 522*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 523*cfb92d14SAndroid Build Coastguard Worker 524*cfb92d14SAndroid Build Coastguard Worker 525*cfb92d14SAndroid Build Coastguard Worker# JoinerRouterKEK TLV (21) 526*cfb92d14SAndroid Build Coastguard Workerclass JoinerRouterKEK(object): 527*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 528*cfb92d14SAndroid Build Coastguard Worker pass 529*cfb92d14SAndroid Build Coastguard Worker 530*cfb92d14SAndroid Build Coastguard Worker 531*cfb92d14SAndroid Build Coastguard Workerclass JoinerRouterKEKFactory(object): 532*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 533*cfb92d14SAndroid Build Coastguard Worker 534*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 535*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 536*cfb92d14SAndroid Build Coastguard Worker 537*cfb92d14SAndroid Build Coastguard Worker 538*cfb92d14SAndroid Build Coastguard Worker# ProvisioningURL TLV (32) 539*cfb92d14SAndroid Build Coastguard Workerclass ProvisioningUrl(object): 540*cfb92d14SAndroid Build Coastguard Worker 541*cfb92d14SAndroid Build Coastguard Worker def __init__(self, url): 542*cfb92d14SAndroid Build Coastguard Worker self._url = url 543*cfb92d14SAndroid Build Coastguard Worker 544*cfb92d14SAndroid Build Coastguard Worker @property 545*cfb92d14SAndroid Build Coastguard Worker def url(self): 546*cfb92d14SAndroid Build Coastguard Worker return self._url 547*cfb92d14SAndroid Build Coastguard Worker 548*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 549*cfb92d14SAndroid Build Coastguard Worker return "ProvisioningUrl(url={})".format(self.url) 550*cfb92d14SAndroid Build Coastguard Worker 551*cfb92d14SAndroid Build Coastguard Worker 552*cfb92d14SAndroid Build Coastguard Workerclass ProvisioningUrlFactory: 553*cfb92d14SAndroid Build Coastguard Worker 554*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 555*cfb92d14SAndroid Build Coastguard Worker url = data.getvalue().decode('utf-8') 556*cfb92d14SAndroid Build Coastguard Worker return ProvisioningUrl(url) 557*cfb92d14SAndroid Build Coastguard Worker 558*cfb92d14SAndroid Build Coastguard Worker 559*cfb92d14SAndroid Build Coastguard Worker# VendorName TLV (33) 560*cfb92d14SAndroid Build Coastguard Workerclass VendorName(object): 561*cfb92d14SAndroid Build Coastguard Worker 562*cfb92d14SAndroid Build Coastguard Worker def __init__(self, vendor_name): 563*cfb92d14SAndroid Build Coastguard Worker self._vendor_name = vendor_name 564*cfb92d14SAndroid Build Coastguard Worker 565*cfb92d14SAndroid Build Coastguard Worker @property 566*cfb92d14SAndroid Build Coastguard Worker def vendor_name(self): 567*cfb92d14SAndroid Build Coastguard Worker return self._vendor_name 568*cfb92d14SAndroid Build Coastguard Worker 569*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 570*cfb92d14SAndroid Build Coastguard Worker return self.vendor_name == other.vendor_name 571*cfb92d14SAndroid Build Coastguard Worker 572*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 573*cfb92d14SAndroid Build Coastguard Worker return "VendorName(vendor_name={})".format(self.vendor_name) 574*cfb92d14SAndroid Build Coastguard Worker 575*cfb92d14SAndroid Build Coastguard Worker 576*cfb92d14SAndroid Build Coastguard Workerclass VendorNameFactory: 577*cfb92d14SAndroid Build Coastguard Worker 578*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 579*cfb92d14SAndroid Build Coastguard Worker vendor_name = data.getvalue().decode('utf-8') 580*cfb92d14SAndroid Build Coastguard Worker return VendorName(vendor_name) 581*cfb92d14SAndroid Build Coastguard Worker 582*cfb92d14SAndroid Build Coastguard Worker 583*cfb92d14SAndroid Build Coastguard Worker# VendorModel TLV (34) 584*cfb92d14SAndroid Build Coastguard Workerclass VendorModel(object): 585*cfb92d14SAndroid Build Coastguard Worker 586*cfb92d14SAndroid Build Coastguard Worker def __init__(self, vendor_model): 587*cfb92d14SAndroid Build Coastguard Worker self._vendor_model = vendor_model 588*cfb92d14SAndroid Build Coastguard Worker 589*cfb92d14SAndroid Build Coastguard Worker @property 590*cfb92d14SAndroid Build Coastguard Worker def vendor_model(self): 591*cfb92d14SAndroid Build Coastguard Worker return self._vendor_model 592*cfb92d14SAndroid Build Coastguard Worker 593*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 594*cfb92d14SAndroid Build Coastguard Worker return self.vendor_model == other.vendor_model 595*cfb92d14SAndroid Build Coastguard Worker 596*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 597*cfb92d14SAndroid Build Coastguard Worker return "VendorModel(vendor_model={})".format(self.vendor_model) 598*cfb92d14SAndroid Build Coastguard Worker 599*cfb92d14SAndroid Build Coastguard Worker 600*cfb92d14SAndroid Build Coastguard Workerclass VendorModelFactory: 601*cfb92d14SAndroid Build Coastguard Worker 602*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 603*cfb92d14SAndroid Build Coastguard Worker vendor_model = data.getvalue().decode('utf-8') 604*cfb92d14SAndroid Build Coastguard Worker return VendorModel(vendor_model) 605*cfb92d14SAndroid Build Coastguard Worker 606*cfb92d14SAndroid Build Coastguard Worker 607*cfb92d14SAndroid Build Coastguard Worker# VendorSWVersion TLV (35) 608*cfb92d14SAndroid Build Coastguard Workerclass VendorSWVersion(object): 609*cfb92d14SAndroid Build Coastguard Worker 610*cfb92d14SAndroid Build Coastguard Worker def __init__(self, vendor_sw_version): 611*cfb92d14SAndroid Build Coastguard Worker self._vendor_sw_version = vendor_sw_version 612*cfb92d14SAndroid Build Coastguard Worker 613*cfb92d14SAndroid Build Coastguard Worker @property 614*cfb92d14SAndroid Build Coastguard Worker def vendor_sw_version(self): 615*cfb92d14SAndroid Build Coastguard Worker return self._vendor_sw_version 616*cfb92d14SAndroid Build Coastguard Worker 617*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 618*cfb92d14SAndroid Build Coastguard Worker return self.vendor_sw_version == other.vendor_sw_version 619*cfb92d14SAndroid Build Coastguard Worker 620*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 621*cfb92d14SAndroid Build Coastguard Worker return "VendorName(vendor_sw_version={})".format(self.vendor_sw_version) 622*cfb92d14SAndroid Build Coastguard Worker 623*cfb92d14SAndroid Build Coastguard Worker 624*cfb92d14SAndroid Build Coastguard Workerclass VendorSWVersionFactory: 625*cfb92d14SAndroid Build Coastguard Worker 626*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 627*cfb92d14SAndroid Build Coastguard Worker vendor_sw_version = data.getvalue() 628*cfb92d14SAndroid Build Coastguard Worker return VendorSWVersion(vendor_sw_version) 629*cfb92d14SAndroid Build Coastguard Worker 630*cfb92d14SAndroid Build Coastguard Worker 631*cfb92d14SAndroid Build Coastguard Worker# VendorData TLV (36) 632*cfb92d14SAndroid Build Coastguard Workerclass VendorData(object): 633*cfb92d14SAndroid Build Coastguard Worker 634*cfb92d14SAndroid Build Coastguard Worker def __init__(self, data): 635*cfb92d14SAndroid Build Coastguard Worker self._vendor_data = data 636*cfb92d14SAndroid Build Coastguard Worker 637*cfb92d14SAndroid Build Coastguard Worker @property 638*cfb92d14SAndroid Build Coastguard Worker def vendor_data(self): 639*cfb92d14SAndroid Build Coastguard Worker return self._vendor_data 640*cfb92d14SAndroid Build Coastguard Worker 641*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 642*cfb92d14SAndroid Build Coastguard Worker return "Vendor(url={})".format(self.vendor_data) 643*cfb92d14SAndroid Build Coastguard Worker 644*cfb92d14SAndroid Build Coastguard Worker 645*cfb92d14SAndroid Build Coastguard Workerclass VendorDataFactory(object): 646*cfb92d14SAndroid Build Coastguard Worker 647*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 648*cfb92d14SAndroid Build Coastguard Worker return VendorData(data) 649*cfb92d14SAndroid Build Coastguard Worker 650*cfb92d14SAndroid Build Coastguard Worker 651*cfb92d14SAndroid Build Coastguard Worker# VendorStackVersion TLV (37) 652*cfb92d14SAndroid Build Coastguard Workerclass VendorStackVersion(object): 653*cfb92d14SAndroid Build Coastguard Worker 654*cfb92d14SAndroid Build Coastguard Worker def __init__(self, stack_vendor_oui, build, rev, minor, major): 655*cfb92d14SAndroid Build Coastguard Worker self._stack_vendor_oui = stack_vendor_oui 656*cfb92d14SAndroid Build Coastguard Worker self._build = build 657*cfb92d14SAndroid Build Coastguard Worker self._rev = rev 658*cfb92d14SAndroid Build Coastguard Worker self._minor = minor 659*cfb92d14SAndroid Build Coastguard Worker self._major = major 660*cfb92d14SAndroid Build Coastguard Worker return 661*cfb92d14SAndroid Build Coastguard Worker 662*cfb92d14SAndroid Build Coastguard Worker @property 663*cfb92d14SAndroid Build Coastguard Worker def stack_vendor_oui(self): 664*cfb92d14SAndroid Build Coastguard Worker return self._stack_vendor_oui 665*cfb92d14SAndroid Build Coastguard Worker 666*cfb92d14SAndroid Build Coastguard Worker @property 667*cfb92d14SAndroid Build Coastguard Worker def build(self): 668*cfb92d14SAndroid Build Coastguard Worker return self._build 669*cfb92d14SAndroid Build Coastguard Worker 670*cfb92d14SAndroid Build Coastguard Worker @property 671*cfb92d14SAndroid Build Coastguard Worker def rev(self): 672*cfb92d14SAndroid Build Coastguard Worker return self._rev 673*cfb92d14SAndroid Build Coastguard Worker 674*cfb92d14SAndroid Build Coastguard Worker @property 675*cfb92d14SAndroid Build Coastguard Worker def minor(self): 676*cfb92d14SAndroid Build Coastguard Worker return self._minor 677*cfb92d14SAndroid Build Coastguard Worker 678*cfb92d14SAndroid Build Coastguard Worker @property 679*cfb92d14SAndroid Build Coastguard Worker def major(self): 680*cfb92d14SAndroid Build Coastguard Worker return self._major 681*cfb92d14SAndroid Build Coastguard Worker 682*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 683*cfb92d14SAndroid Build Coastguard Worker return "VendorStackVersion(vendor_stack_version={}, build={}, rev={}, minor={}, major={})".format( 684*cfb92d14SAndroid Build Coastguard Worker self.stack_vendor_oui, self.build, self.rev, self.minor, self.major) 685*cfb92d14SAndroid Build Coastguard Worker 686*cfb92d14SAndroid Build Coastguard Worker 687*cfb92d14SAndroid Build Coastguard Workerclass VendorStackVersionFactory: 688*cfb92d14SAndroid Build Coastguard Worker 689*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 690*cfb92d14SAndroid Build Coastguard Worker stack_vendor_oui = struct.unpack(">H", data.read(2))[0] 691*cfb92d14SAndroid Build Coastguard Worker rest = struct.unpack(">BBBB", data.read(4)) 692*cfb92d14SAndroid Build Coastguard Worker build = rest[1] << 4 | (0xf0 & rest[2]) 693*cfb92d14SAndroid Build Coastguard Worker rev = 0xF & rest[2] 694*cfb92d14SAndroid Build Coastguard Worker minor = rest[3] & 0xf0 695*cfb92d14SAndroid Build Coastguard Worker major = rest[3] & 0xF 696*cfb92d14SAndroid Build Coastguard Worker return VendorStackVersion(stack_vendor_oui, build, rev, minor, major) 697*cfb92d14SAndroid Build Coastguard Worker 698*cfb92d14SAndroid Build Coastguard Worker 699*cfb92d14SAndroid Build Coastguard Worker# UdpEncapsulation TLV (48) 700*cfb92d14SAndroid Build Coastguard Workerclass UdpEncapsulation(object): 701*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 702*cfb92d14SAndroid Build Coastguard Worker pass 703*cfb92d14SAndroid Build Coastguard Worker 704*cfb92d14SAndroid Build Coastguard Worker 705*cfb92d14SAndroid Build Coastguard Workerclass UdpEncapsulationFactory(object): 706*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 707*cfb92d14SAndroid Build Coastguard Worker 708*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 709*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 710*cfb92d14SAndroid Build Coastguard Worker 711*cfb92d14SAndroid Build Coastguard Worker 712*cfb92d14SAndroid Build Coastguard Worker# Ipv6Address TLV (49) 713*cfb92d14SAndroid Build Coastguard Workerclass Ipv6Address(object): 714*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 715*cfb92d14SAndroid Build Coastguard Worker pass 716*cfb92d14SAndroid Build Coastguard Worker 717*cfb92d14SAndroid Build Coastguard Worker 718*cfb92d14SAndroid Build Coastguard Workerclass Ipv6AddressFactory(object): 719*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 720*cfb92d14SAndroid Build Coastguard Worker 721*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 722*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 723*cfb92d14SAndroid Build Coastguard Worker 724*cfb92d14SAndroid Build Coastguard Worker 725*cfb92d14SAndroid Build Coastguard Worker# PendingTimestamp TLV (51) 726*cfb92d14SAndroid Build Coastguard Workerclass PendingTimestamp(object): 727*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 728*cfb92d14SAndroid Build Coastguard Worker pass 729*cfb92d14SAndroid Build Coastguard Worker 730*cfb92d14SAndroid Build Coastguard Worker 731*cfb92d14SAndroid Build Coastguard Workerclass PendingTimestampFactory(object): 732*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 733*cfb92d14SAndroid Build Coastguard Worker 734*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 735*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 736*cfb92d14SAndroid Build Coastguard Worker 737*cfb92d14SAndroid Build Coastguard Worker 738*cfb92d14SAndroid Build Coastguard Worker# DelayTimer TLV (52) 739*cfb92d14SAndroid Build Coastguard Workerclass DelayTimer(object): 740*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 741*cfb92d14SAndroid Build Coastguard Worker pass 742*cfb92d14SAndroid Build Coastguard Worker 743*cfb92d14SAndroid Build Coastguard Worker 744*cfb92d14SAndroid Build Coastguard Workerclass DelayTimerFactory(object): 745*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 746*cfb92d14SAndroid Build Coastguard Worker 747*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 748*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 749*cfb92d14SAndroid Build Coastguard Worker 750*cfb92d14SAndroid Build Coastguard Worker 751*cfb92d14SAndroid Build Coastguard Worker# ChannelMask TLV (53) 752*cfb92d14SAndroid Build Coastguard Workerclass ChannelMask(object): 753*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 754*cfb92d14SAndroid Build Coastguard Worker pass 755*cfb92d14SAndroid Build Coastguard Worker 756*cfb92d14SAndroid Build Coastguard Worker 757*cfb92d14SAndroid Build Coastguard Workerclass ChannelMaskFactory(object): 758*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 759*cfb92d14SAndroid Build Coastguard Worker 760*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 761*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 762*cfb92d14SAndroid Build Coastguard Worker 763*cfb92d14SAndroid Build Coastguard Worker 764*cfb92d14SAndroid Build Coastguard Worker# Count TLV (54) 765*cfb92d14SAndroid Build Coastguard Workerclass Count(object): 766*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 767*cfb92d14SAndroid Build Coastguard Worker pass 768*cfb92d14SAndroid Build Coastguard Worker 769*cfb92d14SAndroid Build Coastguard Worker 770*cfb92d14SAndroid Build Coastguard Workerclass CountFactory(object): 771*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 772*cfb92d14SAndroid Build Coastguard Worker 773*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 774*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 775*cfb92d14SAndroid Build Coastguard Worker 776*cfb92d14SAndroid Build Coastguard Worker 777*cfb92d14SAndroid Build Coastguard Worker# Period TLV (55) 778*cfb92d14SAndroid Build Coastguard Workerclass Period(object): 779*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 780*cfb92d14SAndroid Build Coastguard Worker pass 781*cfb92d14SAndroid Build Coastguard Worker 782*cfb92d14SAndroid Build Coastguard Worker 783*cfb92d14SAndroid Build Coastguard Workerclass PeriodFactory(object): 784*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 785*cfb92d14SAndroid Build Coastguard Worker 786*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 787*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 788*cfb92d14SAndroid Build Coastguard Worker 789*cfb92d14SAndroid Build Coastguard Worker 790*cfb92d14SAndroid Build Coastguard Worker# ScanDuration TLV (56) 791*cfb92d14SAndroid Build Coastguard Workerclass ScanDuration(object): 792*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 793*cfb92d14SAndroid Build Coastguard Worker pass 794*cfb92d14SAndroid Build Coastguard Worker 795*cfb92d14SAndroid Build Coastguard Worker 796*cfb92d14SAndroid Build Coastguard Workerclass ScanDurationFactory(object): 797*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 798*cfb92d14SAndroid Build Coastguard Worker 799*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 800*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 801*cfb92d14SAndroid Build Coastguard Worker 802*cfb92d14SAndroid Build Coastguard Worker 803*cfb92d14SAndroid Build Coastguard Worker# EnergyList TLV (57) 804*cfb92d14SAndroid Build Coastguard Workerclass EnergyList(object): 805*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 806*cfb92d14SAndroid Build Coastguard Worker pass 807*cfb92d14SAndroid Build Coastguard Worker 808*cfb92d14SAndroid Build Coastguard Worker 809*cfb92d14SAndroid Build Coastguard Workerclass EnergyListFactory(object): 810*cfb92d14SAndroid Build Coastguard Worker # TODO: Not implemented yet 811*cfb92d14SAndroid Build Coastguard Worker 812*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 813*cfb92d14SAndroid Build Coastguard Worker raise NotImplementedError("TODO: Not implemented yet") 814*cfb92d14SAndroid Build Coastguard Worker 815*cfb92d14SAndroid Build Coastguard Worker 816*cfb92d14SAndroid Build Coastguard Worker# Discovery Request TLV (128) 817*cfb92d14SAndroid Build Coastguard Workerclass DiscoveryRequest(object): 818*cfb92d14SAndroid Build Coastguard Worker 819*cfb92d14SAndroid Build Coastguard Worker def __init__(self, version, joiner_flag): 820*cfb92d14SAndroid Build Coastguard Worker self._version = version 821*cfb92d14SAndroid Build Coastguard Worker self._joiner_flag = joiner_flag 822*cfb92d14SAndroid Build Coastguard Worker 823*cfb92d14SAndroid Build Coastguard Worker @property 824*cfb92d14SAndroid Build Coastguard Worker def version(self): 825*cfb92d14SAndroid Build Coastguard Worker return self._version 826*cfb92d14SAndroid Build Coastguard Worker 827*cfb92d14SAndroid Build Coastguard Worker @property 828*cfb92d14SAndroid Build Coastguard Worker def joiner_flag(self): 829*cfb92d14SAndroid Build Coastguard Worker return self._joiner_flag 830*cfb92d14SAndroid Build Coastguard Worker 831*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 832*cfb92d14SAndroid Build Coastguard Worker return (isinstance(self, type(other)) and self.version == other.version and 833*cfb92d14SAndroid Build Coastguard Worker self.joiner_flag == other.joiner_flag) 834*cfb92d14SAndroid Build Coastguard Worker 835*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 836*cfb92d14SAndroid Build Coastguard Worker return "DiscoveryRequest(version={}, joiner_flag={})".format(self.version, self.joiner_flag) 837*cfb92d14SAndroid Build Coastguard Worker 838*cfb92d14SAndroid Build Coastguard Worker 839*cfb92d14SAndroid Build Coastguard Workerclass DiscoveryRequestFactory(object): 840*cfb92d14SAndroid Build Coastguard Worker 841*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 842*cfb92d14SAndroid Build Coastguard Worker data_byte = struct.unpack(">B", data.read(1))[0] 843*cfb92d14SAndroid Build Coastguard Worker version = (data_byte & 0xf0) >> 4 844*cfb92d14SAndroid Build Coastguard Worker joiner_flag = (data_byte & 0x08) >> 3 845*cfb92d14SAndroid Build Coastguard Worker 846*cfb92d14SAndroid Build Coastguard Worker return DiscoveryRequest(version, joiner_flag) 847*cfb92d14SAndroid Build Coastguard Worker 848*cfb92d14SAndroid Build Coastguard Worker 849*cfb92d14SAndroid Build Coastguard Worker# Discovery Response TLV (128) 850*cfb92d14SAndroid Build Coastguard Workerclass DiscoveryResponse(object): 851*cfb92d14SAndroid Build Coastguard Worker 852*cfb92d14SAndroid Build Coastguard Worker def __init__(self, version, native_flag): 853*cfb92d14SAndroid Build Coastguard Worker self._version = version 854*cfb92d14SAndroid Build Coastguard Worker self._native_flag = native_flag 855*cfb92d14SAndroid Build Coastguard Worker 856*cfb92d14SAndroid Build Coastguard Worker @property 857*cfb92d14SAndroid Build Coastguard Worker def version(self): 858*cfb92d14SAndroid Build Coastguard Worker return self._version 859*cfb92d14SAndroid Build Coastguard Worker 860*cfb92d14SAndroid Build Coastguard Worker @property 861*cfb92d14SAndroid Build Coastguard Worker def native_flag(self): 862*cfb92d14SAndroid Build Coastguard Worker return self._native_flag 863*cfb92d14SAndroid Build Coastguard Worker 864*cfb92d14SAndroid Build Coastguard Worker def __eq__(self, other): 865*cfb92d14SAndroid Build Coastguard Worker return (isinstance(self, type(other)) and self.version == other.version and 866*cfb92d14SAndroid Build Coastguard Worker self.native_flag == other.native_flag) 867*cfb92d14SAndroid Build Coastguard Worker 868*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 869*cfb92d14SAndroid Build Coastguard Worker return "DiscoveryResponse(version={}, native_flag={})".format(self.version, self.native_flag) 870*cfb92d14SAndroid Build Coastguard Worker 871*cfb92d14SAndroid Build Coastguard Worker 872*cfb92d14SAndroid Build Coastguard Workerclass DiscoveryResponseFactory(object): 873*cfb92d14SAndroid Build Coastguard Worker 874*cfb92d14SAndroid Build Coastguard Worker def parse(self, data, message_info): 875*cfb92d14SAndroid Build Coastguard Worker data_byte = struct.unpack(">B", data.read(1))[0] 876*cfb92d14SAndroid Build Coastguard Worker version = (data_byte & 0xf0) >> 4 877*cfb92d14SAndroid Build Coastguard Worker native_flag = (data_byte & 0x08) >> 3 878*cfb92d14SAndroid Build Coastguard Worker 879*cfb92d14SAndroid Build Coastguard Worker return DiscoveryResponse(version, native_flag) 880*cfb92d14SAndroid Build Coastguard Worker 881*cfb92d14SAndroid Build Coastguard Worker 882*cfb92d14SAndroid Build Coastguard Workerclass MeshCopCommand(object): 883*cfb92d14SAndroid Build Coastguard Worker 884*cfb92d14SAndroid Build Coastguard Worker def __init__(self, _type, tlvs): 885*cfb92d14SAndroid Build Coastguard Worker self._type = _type 886*cfb92d14SAndroid Build Coastguard Worker self._tlvs = tlvs 887*cfb92d14SAndroid Build Coastguard Worker 888*cfb92d14SAndroid Build Coastguard Worker @property 889*cfb92d14SAndroid Build Coastguard Worker def type(self): 890*cfb92d14SAndroid Build Coastguard Worker return self._type 891*cfb92d14SAndroid Build Coastguard Worker 892*cfb92d14SAndroid Build Coastguard Worker @property 893*cfb92d14SAndroid Build Coastguard Worker def tlvs(self): 894*cfb92d14SAndroid Build Coastguard Worker return self._tlvs 895*cfb92d14SAndroid Build Coastguard Worker 896*cfb92d14SAndroid Build Coastguard Worker def __repr__(self): 897*cfb92d14SAndroid Build Coastguard Worker tlvs_str = ", ".join(["{}".format(tlv) for tlv in self.tlvs]) 898*cfb92d14SAndroid Build Coastguard Worker return "MeshCopCommand(type={}, tlvs=[{}])".format(self.type, tlvs_str) 899*cfb92d14SAndroid Build Coastguard Worker 900*cfb92d14SAndroid Build Coastguard Worker 901*cfb92d14SAndroid Build Coastguard Workerdef create_deault_mesh_cop_msg_type_map(): 902*cfb92d14SAndroid Build Coastguard Worker return { 903*cfb92d14SAndroid Build Coastguard Worker 'JOIN_FIN.req': MeshCopMessageType.JOIN_FIN_REQ, 904*cfb92d14SAndroid Build Coastguard Worker 'JOIN_FIN.rsp': MeshCopMessageType.JOIN_FIN_RSP, 905*cfb92d14SAndroid Build Coastguard Worker 'JOIN_ENT.ntf': MeshCopMessageType.JOIN_ENT_NTF, 906*cfb92d14SAndroid Build Coastguard Worker 'JOIN_ENT.rsp': MeshCopMessageType.JOIN_ENT_RSP, 907*cfb92d14SAndroid Build Coastguard Worker } 908*cfb92d14SAndroid Build Coastguard Worker 909*cfb92d14SAndroid Build Coastguard Worker 910*cfb92d14SAndroid Build Coastguard Workerclass MeshCopCommandFactory: 911*cfb92d14SAndroid Build Coastguard Worker 912*cfb92d14SAndroid Build Coastguard Worker def __init__(self, tlvs_factories): 913*cfb92d14SAndroid Build Coastguard Worker self._tlvs_factories = tlvs_factories 914*cfb92d14SAndroid Build Coastguard Worker self._mesh_cop_msg_type_map = create_deault_mesh_cop_msg_type_map() 915*cfb92d14SAndroid Build Coastguard Worker 916*cfb92d14SAndroid Build Coastguard Worker def _get_length(self, data): 917*cfb92d14SAndroid Build Coastguard Worker return ord(data.read(1)) 918*cfb92d14SAndroid Build Coastguard Worker 919*cfb92d14SAndroid Build Coastguard Worker def _get_tlv_factory(self, _type): 920*cfb92d14SAndroid Build Coastguard Worker try: 921*cfb92d14SAndroid Build Coastguard Worker return self._tlvs_factories[_type] 922*cfb92d14SAndroid Build Coastguard Worker except KeyError: 923*cfb92d14SAndroid Build Coastguard Worker logging.error('Could not find TLV factory. Unsupported TLV type: {}'.format(_type)) 924*cfb92d14SAndroid Build Coastguard Worker return UnknownTlvFactory(_type) 925*cfb92d14SAndroid Build Coastguard Worker 926*cfb92d14SAndroid Build Coastguard Worker def _parse_tlv(self, data): 927*cfb92d14SAndroid Build Coastguard Worker _type = TlvType(ord(data.read(1))) 928*cfb92d14SAndroid Build Coastguard Worker length = self._get_length(data) 929*cfb92d14SAndroid Build Coastguard Worker value = data.read(length) 930*cfb92d14SAndroid Build Coastguard Worker factory = self._get_tlv_factory(_type) 931*cfb92d14SAndroid Build Coastguard Worker return factory.parse(io.BytesIO(value), None) # message_info not needed here 932*cfb92d14SAndroid Build Coastguard Worker 933*cfb92d14SAndroid Build Coastguard Worker def _get_mesh_cop_msg_type(self, msg_type_str): 934*cfb92d14SAndroid Build Coastguard Worker try: 935*cfb92d14SAndroid Build Coastguard Worker return self._mesh_cop_msg_type_map[msg_type_str] 936*cfb92d14SAndroid Build Coastguard Worker except KeyError: 937*cfb92d14SAndroid Build Coastguard Worker raise KeyError('Mesh cop message type not found: {}'.format(msg_type_str)) 938*cfb92d14SAndroid Build Coastguard Worker 939*cfb92d14SAndroid Build Coastguard Worker def parse(self, cmd_type_str, data): 940*cfb92d14SAndroid Build Coastguard Worker cmd_type = self._get_mesh_cop_msg_type(cmd_type_str) 941*cfb92d14SAndroid Build Coastguard Worker 942*cfb92d14SAndroid Build Coastguard Worker tlvs = [] 943*cfb92d14SAndroid Build Coastguard Worker while data.tell() < len(data.getvalue()): 944*cfb92d14SAndroid Build Coastguard Worker tlv = self._parse_tlv(data) 945*cfb92d14SAndroid Build Coastguard Worker tlvs.append(tlv) 946*cfb92d14SAndroid Build Coastguard Worker 947*cfb92d14SAndroid Build Coastguard Worker return MeshCopCommand(cmd_type, tlvs) 948*cfb92d14SAndroid Build Coastguard Worker 949*cfb92d14SAndroid Build Coastguard Worker 950*cfb92d14SAndroid Build Coastguard Workerdef create_default_mesh_cop_tlv_factories(): 951*cfb92d14SAndroid Build Coastguard Worker return { 952*cfb92d14SAndroid Build Coastguard Worker TlvType.STATE: StateFactory(), 953*cfb92d14SAndroid Build Coastguard Worker TlvType.PROVISIONING_URL: ProvisioningUrlFactory(), 954*cfb92d14SAndroid Build Coastguard Worker TlvType.VENDOR_NAME: VendorNameFactory(), 955*cfb92d14SAndroid Build Coastguard Worker TlvType.VENDOR_MODEL: VendorModelFactory(), 956*cfb92d14SAndroid Build Coastguard Worker TlvType.VENDOR_SW_VERSION: VendorSWVersionFactory(), 957*cfb92d14SAndroid Build Coastguard Worker TlvType.VENDOR_DATA: VendorDataFactory(), 958*cfb92d14SAndroid Build Coastguard Worker TlvType.VENDOR_STACK_VERSION: VendorStackVersionFactory(), 959*cfb92d14SAndroid Build Coastguard Worker } 960*cfb92d14SAndroid Build Coastguard Worker 961*cfb92d14SAndroid Build Coastguard Worker 962*cfb92d14SAndroid Build Coastguard Workerclass ThreadDiscoveryTlvsFactory(SubTlvsFactory): 963*cfb92d14SAndroid Build Coastguard Worker 964*cfb92d14SAndroid Build Coastguard Worker def __init__(self, sub_tlvs_factories): 965*cfb92d14SAndroid Build Coastguard Worker super(ThreadDiscoveryTlvsFactory, self).__init__(sub_tlvs_factories) 966