Exemplo n.º 1
0
    def __init__(self, loop, serial_port, baudrate=115200):
        super().__init__(sub_topic_list=[b'message_s', b'prov_s'],
                         pub_topic_list=[b'message', b'prov', b'beacon'])

        self.ser_log = log_sys.get_logger('dongle.serial')
        self.ch_log = log_sys.get_logger('dongle.channel')
        self.ser_log.set_level(DEBUG)
        self.ch_log.set_level(DEBUG)

        self.loop = loop
        self.serial_port = serial_port
        self.baudrate = baudrate
        self.serial = Serial(self.loop, self.serial_port, self.baudrate)
        self.write_serial_queue = asyncio.Queue()

        self.caches = {
            b'message': [],
            b'beacon': [],
            b'prov': []
        }

        self.loop.run_until_complete(self._reset_dongle())

        self.all_tasks += [self._read_serial_task(),
                           self._transport_message_task(),
                           self._write_serial_task(),
                           self._clear_caches_task()]
Exemplo n.º 2
0
    def __init__(self, loop, baudrate=115200):
        self.log = log_sys.get_logger('dongle.serial')
        self.log.set_level(INFO)

        self.loop = loop
        self.baudrate = baudrate
        self.expected_result = b'@reset 0 00 bm9uZQ==\r\n***** BLE Mesh Dongle v1.0 *****\r\n'
Exemplo n.º 3
0
    def __init__(self, sub_topic_list: list, pub_topic_list: list):
        self.pub_topic_list = pub_topic_list + [b'disconnect']
        self.messages_to_send = asyncio.Queue()
        self.messages_received = asyncio.Queue()

        self.client_log = log_sys.get_logger('client')
        self.client_log.set_level(INFO)

        self.pub_url = 'tcp://127.0.0.1:'
        self.broker_listen_url = 'tcp://127.0.0.1:9500'
        self.broker_pub_url = 'tcp://127.0.0.1:9501'

        self.ctx = Context.instance()

        self.pub_sock = self.ctx.socket(zmq.PUB)
        self.sub_sock = self.ctx.socket(zmq.SUB)

        self.sub_sock.connect(self.broker_pub_url)

        sub_topic_list += [b'disconnect']
        for st in sub_topic_list:
            self.sub_sock.setsockopt(zmq.SUBSCRIBE, st)

        self.loop = None
        self.tasks_h = None
        self.is_connected = False
        self.client_tasks = [self._subscribe_task(), self._publish_task()]
        self.all_tasks = []
Exemplo n.º 4
0
    def __init__(self):
        super().__init__(sub_topic_list=[b'beacon'], pub_topic_list=[])

        self.log = log_sys.get_logger('list_devices')
        self.log.set_level(INFO)
        self.index = 1
        self.cache = []

        self.all_tasks += [self.list_devices_task()]
Exemplo n.º 5
0
    def __init__(self):
        super().__init__(sub_topic_list=[b'message'],
                         pub_topic_list=[b'message_s'])
        self.log = log_sys.get_logger('element')
        self.log.set_level(INFO)

        self.tr_layer = TransportLayer(send_queue=self.messages_to_send,
                                       recv_queue=self.messages_received)

        self.all_tasks += [self.tr_layer.net_layer.recv_pdu()]
Exemplo n.º 6
0
    def __init__(self, send_queue, recv_queue):
        self.hard_ctx = HardContext(seq=0,
                                    ttl=2,
                                    is_ctrl_msg=True,
                                    seq_zero=0,
                                    seg_o=0,
                                    seg_n=0,
                                    szmic=0)
        self.send_queue = send_queue
        self.recv_queue = recv_queue

        self.log = log_sys.get_logger('network_layer')
        self.log.set_level(INFO)

        # (transport_pdu: bytes, soft_ctx: SoftContext)
        self.transport_pdus = asyncio.Queue()
Exemplo n.º 7
0
    def __init__(self, loop):
        self.loop = loop
        self.publish_queue = asyncio.Queue()

        self.broker_log = log_sys.get_logger('broker')
        self.broker_log.set_level(INFO)

        self.listen_url = 'tcp://127.0.0.1:9500'
        self.pub_url = 'tcp://127.0.0.1:9501'
        self.ctx = Context.instance()

        self.pub_sock = self.ctx.socket(zmq.PUB)
        self.listen_sock = self.ctx.socket(zmq.REP)
        self.subs = {}

        self.pub_sock.bind(self.pub_url)
        self.listen_sock.bind(self.listen_url)
Exemplo n.º 8
0
    def __init__(self, send_queue, recv_queue):
        self.net_layer = NetworkLayer(send_queue=send_queue,
                                      recv_queue=recv_queue)

        self.log = log_sys.get_logger('transport_layer')
        self.log.set_level(INFO)
Exemplo n.º 9
0
    def __init__(self,
                 loop,
                 device_uuid: bytes,
                 netkey: bytes,
                 key_index: bytes,
                 iv_index: bytes,
                 address: bytes,
                 flags=b'\x00',
                 attention_duration=5,
                 debug=False):
        super().__init__(sub_topic_list=[b'prov'], pub_topic_list=[b'prov_s'])

        self.log = log_sys.get_logger('provisioner')
        if debug:
            self.log.set_level(DEBUG)
        else:
            self.log.set_level(INFO)

        self.adv_mtu = 24
        self.start_pdu = 0
        self.cont_pdu = 2

        self.loop = loop
        self.device_info = DeviceInfo(uuid=device_uuid,
                                      attention=attention_duration,
                                      netkey=netkey,
                                      key_index=key_index,
                                      flags=flags,
                                      iv_index=iv_index,
                                      address=address)
        self.prov_ctx = ProvisioningContext(device_link=b'\xaa\xbb\xcc\xdd',
                                            client_tr_number=0x00,
                                            node_tr_number=0x80,
                                            public_key=None,
                                            private_key=None,
                                            ecdh_secret=None,
                                            random_provisioner=None,
                                            confirmation_key=None,
                                            auth_value=None,
                                            invite_pdu=None,
                                            capabilities_pdu=None,
                                            start_pdu=None,
                                            node_confirmation=None,
                                            confirmation_salt=None,
                                            random_device=None,
                                            node_public_key=None)
        self.g_recv_ctx = GenericProvContext(segn=0,
                                             total_length=0,
                                             fcs=0,
                                             current_index=0,
                                             content=b'')

        sk = SigningKey.generate(curve=NIST256p)
        vk = sk.get_verifying_key()
        self.prov_ctx.private_key = sk.privkey.secret_multiplier
        self.prov_ctx.public_key = vk.pubkey.point

        self.prov_ctx.random_provisioner = get_random_bytes(16)

        self.devkey = None

        self.all_tasks += [self._provisioning_device()]