Exemple #1
0
 def __netkey_status_handler(self, opcode, message):
     status, netkey_index = struct.unpack("<BH", message.data)
     netkey_index = mt.KeyIndex(netkey_index)
     status = AccessStatus(status)
     self.logger.info("Netkey status: %s", status)
     if status == AccessStatus.SUCCESS:
         node = self.node_get(message.meta["src"])
         if netkey_index not in node.net_keys:
             node.net_keys.append(netkey_index)
         self.db_save()
         self.logger.info("Added subnet %d to node %04x", netkey_index,
                          message.meta["src"])
Exemple #2
0
 def __model_sig_app_list_handler(self, opcode, message):
     status, element_address, model_id = struct.unpack(
         "<BHH", message.data[0:5])
     status = AccessStatus(status)
     self.logger.info("SIG Model App List status: %s", status)
     if status == AccessStatus.SUCCESS:
         appkeys = ConfigurationClient._unpack_key_ind(message.data[5:])
         model = self.model_get(element_address, mt.ModelId(model_id))
         model.bind = appkeys
         self.db_save()
         self.logger.info("SIG model %04x has appkey(s) %r bound", model_id,
                          appkeys)
Exemple #3
0
 def __key_refresh_phase_status_handler(self, opcode, message):
     status, netkey_index, phase = struct.unpack("<BHB", message.data)
     status = AccessStatus(status)
     self.logger.info("Key refresh status: %s", status)
     if status == AccessStatus.SUCCESS:
         node = self.node_get(message.meta["src"])
         for key in node.net_keys:
             if key.index == netkey_index:
                 key.phase = mt.KeyRefreshPhase(phase)
                 self.db_save()
                 self.logger.info(
                     "Netkey phase %r for subnet %r at node %04x", phase,
                     netkey_index, node.unicastAddress)
Exemple #4
0
    def __node_identity_status_handler(self, opcode, message):
        status, netkey_index, identity = struct.unpack("<BHB", message.data)
        status = AccessStatus(status)
        self.logger.info("Node identity status: %s", status)
        if status == AccessStatus.SUCCESS:
            if identity == 0:
                state = "stopped"
            elif identity == 1:
                state = "running"
            else:
                state = "not supported"

            self.logger.info("Current node identity for subnet %d is %s",
                             netkey_index, state)
Exemple #5
0
 def __heartbeat_subscription_status_handler(self, opcode, message):
     status, src, dst, period_log, count_log, min_hops, max_hops = struct.unpack(
         "<BHHBBBB", message.data)
     status = AccessStatus(status)
     self.logger.info("Heartbeat subscription status: %s", status)
     if status == AccessStatus.SUCCESS:
         if period_log == 0:
             period = 0
         else:
             period = 2**(period_log - 1)
         self.logger.info(
             "Heartbeat subscription state: " +
             "src: %04x, dst: %04x, period: %ds, count: %d, min/max: %d/%d",
             src, dst, period, count_log, min_hops, max_hops)
Exemple #6
0
 def __model_publication_status_handler(self, opcode, message):
     status, element_address = struct.unpack("<BH", message.data[0:3])
     status = AccessStatus(status)
     self.logger.info("Model publication status: %s", status)
     if status == AccessStatus.SUCCESS:
         publish = mt.Publish.unpack(message.data[3:10])
         if self._tmp_address:
             publish.address = mt.any_address(self._tmp_address)
             self._tmp_address = None
         model = self.model_get(element_address,
                                mt.ModelId.unpack(message.data[10:]))
         model.publish = publish
         self.db_save()
         self.logger.info(
             "Publication status for model %r at element %r to %r",
             model.model_id, element_address, publish)
Exemple #7
0
    def __model_subscription_status_handler(self, opcode, message):
        status, element_address = struct.unpack("<BH", message.data[0:3])
        status = AccessStatus(status)
        self.logger.info("Model subscription status: %s", status)
        if status == AccessStatus.SUCCESS:
            # address = struct.unpack("<H", message[3:5])
            address = self._tmp_address
            self._tmp_address = None
            model_id = mt.ModelId.unpack(message.data[5:])
            model = self.model_get(element_address, model_id)
            if address not in model.subscribe:
                model.subscribe.append(mt.group_address(address))

            self.db_save()
            self.logger.info(
                "Added subscription %r to model %r at element %04x", address,
                model_id, element_address)
Exemple #8
0
    def __model_sig_subscription_list_handler(self, opcode, message):
        status, element_address, model_id = struct.unpack(
            "<BHH", message.data[0:5])
        status = AccessStatus(status)
        self.logger.info("SIG Model Subscription List status: %s", status)
        if status == AccessStatus.SUCCESS:
            if len(message.data) > 5:
                addresses = struct.unpack(
                    "<" + "H" * (len(message.data[5:]) // 2), message.data[5:])
                addresses = [mt.group_address(a) for a in addresses]
            else:
                addresses = []

            model = self.model_get(element_address, mt.ModelId(model_id))
            model.subscribe = addresses
            self.db_save()
            self.logger.info("SIG model %04x has addresse(s) %r bound",
                             model_id, addresses)
Exemple #9
0
 def __heartbeat_publication_status_handler(self, opcode, message):
     status, dst, count_log, period_log, ttl, features, netkey_index = struct.unpack(
         "<BHBBBHH", message.data)
     status = AccessStatus(status)
     self.logger.info("Heartbeat publication status: %s", status)
     if status == AccessStatus.SUCCESS:
         count = 0 if count_log == 0 else 2**(count_log - 1)
         period = 0 if period_log == 0 else 2**(period_log - 1)
         features = {
             "relay": (features & (1 << 0)) > 0,
             "proxy": (features & (1 << 1)) > 0,
             "friend": (features & (1 << 2)) > 0,
             "lowPower": (features & (1 << 3)) > 0
         }
         self.logger.info(
             "Heartbeat publication state: " +
             "dst: %04x, count: %d, period: %ds, features: %r, subnet: %d",
             dst, count, period, features, netkey_index)
Exemple #10
0
 def __appkey_status_handler(self, opcode, message):
     status = AccessStatus(message.data[0])
     netkey_index, appkey_index = mt.KeyIndex.unpack(message.data[1:4])
     self.logger.info("Appkey status: %s", status)
     if status in [
             AccessStatus.SUCCESS, AccessStatus.KEY_INDEX_ALREADY_STORED
     ]:
         node = self.node_get(message.meta["src"])
         if self.previous_command == "add" and appkey_index not in node.app_keys:
             node.app_keys.append(appkey_index)
         elif self.previous_command == "update":
             pass
         elif self.previous_command == "delete" and appkey_index in node.app_keys:
             node.app_keys.remove(appkey_index)
         self.db_save()
         self.logger.info(
             "Appkey %s %d succeded for subnet %d at node %04x",
             self.previous_command, appkey_index, netkey_index,
             message.meta["src"])
Exemple #11
0
    def __model_app_status_handler(self, opcode, message):
        status, element_address, appkey_index = struct.unpack(
            "<BHH", message.data[:5])
        status = AccessStatus(status)
        model_id = mt.ModelId.unpack(message.data[5:])
        element_address = mt.UnicastAddress(element_address)
        appkey_index = mt.KeyIndex(appkey_index)

        self.logger.info("Model app bind status: %s", status)
        if status == AccessStatus.SUCCESS:
            model = self.model_get(element_address, model_id)

            # Was last command a bind or unbind?
            if self.previous_command == "bind" and appkey_index not in model.bind:
                model.bind.append(appkey_index)
            elif appkey_index in model.bind:
                model.bind.remove(appkey_index)

            self.db_save()
            self.logger.info("Appkey %s %d to model %r at %04x",
                             self.previous_command, appkey_index, model_id,
                             element_address)
Exemple #12
0
    def __appkey_list_handler(self, opcode, message):
        status, netkey_index = struct.unpack("<BH", message.data[0:3])
        status = AccessStatus(status)
        self.logger.info("Appkey list status: %s", status)
        if status == AccessStatus.SUCCESS:
            appkeys = ConfigurationClient._unpack_key_ind(message.data[3:])
            node = self.node_get(message.meta["src"])

            # Add newly discovered keys
            for index in appkeys:
                if ((self.prov_db.app_keys[index].bound_net_key == netkey_index
                     and index not in node.app_keys)):
                    node.app_keys.append(index)

            # Remove old dead keys
            for index in node.app_keys:
                if ((self.prov_db.app_keys[index].bound_net_key == netkey_index
                     and index not in appkeys)):
                    node.app_keys.remove(index)

            self.db_save()
            self.logger.info("Node %04x has appkeys: %r", message.meta["src"],
                             appkeys)