Пример #1
0
    def set_device_id(self, newid):
        if self.__id_form__ == 0:
            self.conn.set_table_data(DEVICE_IDENT_TBL,
                                     (newid + (' ' * (20 - len(newid)))))
        else:
            self.conn.set_table_data(DEVICE_IDENT_TBL,
                                     (newid + (' ' * (10 - len(newid)))))

        self.conn.send(
            C1218WriteRequest(PROC_INITIATE_TBL,
                              '\x46\x08\x1c\x03\x0b\x0c\x09\x0f\x12'))
        data = self.conn.recv()
        if data != '\x00':
            pass

        try:
            ident_table = self.conn.get_table_data(DEVICE_IDENT_TBL)
        except C1218ReadTableError:
            return 1

        if self.__id_form__ == 0 and len(ident_table) != 20:
            raise C1219ParseError(
                'expected to read more data from DEVICE_IDENT_TBL',
                DEVICE_IDENT_TBL)
        elif self.__id_form__ != 0 and len(ident_table) != 10:
            raise C1219ParseError(
                'expected to read more data from DEVICE_IDENT_TBL',
                DEVICE_IDENT_TBL)
        if not ident_table.startswith(newid):
            return 2
        self.__device_id__ = newid
        return 0
Пример #2
0
	def updateLastCallStatuses(self):
		tmp = 0
		call_status_table = self.conn.get_table_data(CALL_STATUS_TBL)
		if (len(call_status_table) % self.nbr_originate_numbers) != 0:
			raise C1219ParseError('expected to read more data from CALL_STATUS_TBL', CALL_STATUS_TBL)
		call_status_rcd_length = (len(call_status_table) / self.nbr_originate_numbers)
		while tmp < self.nbr_originate_numbers:
			self.__originating_numbers__[tmp]['status'] = ord(call_status_table[0])
			call_status_table = call_status_table[call_status_rcd_length:]
			tmp += 1
Пример #3
0
    def __init__(self, conn):
        """
		Initializes a new instance of the class and reads tables from the
		corresponding decades to populate information.

		@type conn: c1218.connection.Connection
		@param conn: The driver to be used for interacting with the
		necessary tables.
		"""
        self.conn = conn
        general_config_table = self.conn.get_table_data(GEN_CONFIG_TBL)
        actual_log_table = self.conn.get_table_data(ACT_LOG_TBL)
        history_log_data_table = self.conn.get_table_data(HISTORY_LOG_DATA_TBL)

        if len(general_config_table) < 19:
            raise C1219ParseError(
                'expected to read more data from GEN_CONFIG_TBL',
                GEN_CONFIG_TBL)
        if len(actual_log_table) < 9:
            raise C1219ParseError(
                'expected to read more data from ACT_LOG_TBL', ACT_LOG_TBL)
        if len(history_log_data_table) < 11:
            raise C1219ParseError(
                'expected to read more data from HISTORY_LOG_DATA_TBL',
                HISTORY_LOG_DATA_TBL)

        ### Parse GEN_CONFIG_TBL ###
        tm_format = ord(general_config_table[1]) & 7
        std_version_no = ord(general_config_table[11])
        std_revision_no = ord(general_config_table[12])

        ### Parse ACT_LOG_TBL ###
        log_flags = ord(actual_log_table[0])
        event_number_flag = bool(log_flags & 1)
        hist_date_time_flag = bool(log_flags & 2)
        hist_seq_nbr_flag = bool(log_flags & 4)
        hist_inhibit_ovf_flag = bool(log_flags & 8)
        event_inhibit_ovf_flag = bool(log_flags & 16)
        nbr_std_events = ord(actual_log_table[1])
        nbr_mfg_events = ord(actual_log_table[2])
        hist_data_length = ord(actual_log_table[3])
        event_data_length = ord(actual_log_table[4])
        self.__nbr_history_entries__, self.__nbr_event_entries__ = struct.unpack(
            self.conn.c1219_endian + 'HH', actual_log_table[5:9])
        if std_version_no > 1:
            ext_log_flags = ord(actual_log_table[9])
            nbr_program_tables = struct.unpack(self.conn.c1219_endian + 'H',
                                               actual_log_table[10:12])
        else:
            ext_log_flags = None
            nbr_program_tables = None
        ### Parse HISTORY_LOG_DATA_TBL ###
        order_flag = ord(history_log_data_table[0]) & 1
        overflow_flag = ord(history_log_data_table[0]) & 2
        list_type_flag = ord(history_log_data_table[0]) & 4
        inhibit_overflow_flag = ord(history_log_data_table[0]) & 8
        nbr_valid_entries, last_entry_element, last_entry_seq_num, nbr_unread_entries = struct.unpack(
            self.conn.c1219_endian + 'HHIH', history_log_data_table[1:11])

        log_data = history_log_data_table[11:]
        size_of_log_rcd = hist_data_length + 4  # hist_data_length + (SIZEOF(USER_ID) + SIZEOF(TABLE_IDB_BFLD))
        if hist_date_time_flag:
            size_of_log_rcd += LTIME_LENGTH[tm_format]
        if event_number_flag:
            size_of_log_rcd += 2
        if hist_seq_nbr_flag:
            size_of_log_rcd += 2

        if len(log_data) != (size_of_log_rcd * self.nbr_history_entries):
            raise C1219ParseError(
                'log data size does not align with expected record size, possibly corrupt',
                HISTORY_LOG_DATA_TBL)

        entry_idx = 0
        self.__logs__ = []
        while entry_idx < self.nbr_history_entries:
            self.__logs__.append(
                get_history_entry_record(self.conn.c1219_endian,
                                         hist_date_time_flag, tm_format,
                                         event_number_flag, hist_seq_nbr_flag,
                                         log_data[:size_of_log_rcd]))
            log_data = log_data[size_of_log_rcd:]
            entry_idx += 1
Пример #4
0
    def __init__(self, conn):
        """
		Initializes a new instance of the class and reads tables from the
		corresponding decades to populate information.
		
		@type conn: c1218.connection.Connection
		@param conn: The driver to be used for interacting with the
		necessary tables.
		"""
        self.conn = conn
        actual_telephone_table = self.conn.getTableData(ACT_TELEPHONE_TBL)
        global_parameters_table = self.conn.getTableData(GLOBAL_PARAMETERS_TBL)
        originate_parameters_table = self.conn.getTableData(
            ORIGINATE_PARAMETERS_TBL)
        originate_schedule_table = self.conn.getTableData(
            ORIGINATE_SCHEDULE_TBL)
        answer_parameters_table = self.conn.getTableData(ANSWER_PARAMETERS_TBL)

        if (actual_telephone_table) < 14:
            raise C1219ParseError(
                'expected to read more data from ACT_TELEPHONE_TBL',
                ACT_TELEPHONE_TBL)

        info = {}
        ### Parse ACT_TELEPHONE_TBL ###
        use_extended_status = bool(ord(actual_telephone_table[0]) & 128)
        prefix_length = ord(actual_telephone_table[4])
        nbr_originate_numbers = ord(actual_telephone_table[5])
        phone_number_length = ord(actual_telephone_table[6])
        bit_rate_settings = (
            ord(actual_telephone_table[1]) >>
            3) & 3  # not the actual settings but rather where they are defined
        self.__can_answer__ = bool(ord(actual_telephone_table[0]) & 1)
        self.__use_extended_status__ = use_extended_status
        self.__nbr_originate_numbers__ = nbr_originate_numbers

        ### Parse GLOBAL_PARAMETERS_TBL ###
        self.__psem_identity__ = ord(global_parameters_table[0])
        if bit_rate_settings == 1:
            if len(global_parameters_table) < 5:
                raise C1219ParseError(
                    'expected to read more data from GLOBAL_PARAMETERS_TBL',
                    GLOBAL_PARAMETERS_TBL)
            self.__global_bit_rate__ = unpack(conn.c1219_endian + 'I',
                                              global_parameters_table[1:5])[0]

        ### Parse ORIGINATE_PARAMETERS_TBL ###
        if bit_rate_settings == 2:
            self.__originate_bit_rate__ = unpack(
                conn.c1219_endian + 'I', originate_parameters_table[0:4])[0]
            originate_parameters_table = originate_parameters_table[4:]
        self.__dial_delay__ = ord(originate_parameters_table[0])
        originate_parameters_table = originate_parameters_table[1:]

        if prefix_length != 0:
            self.__prefix_number__ = originate_parameters_table[:prefix_length]
            originate_parameters_table = originate_parameters_table[
                prefix_length:]

        self.__originating_numbers__ = {}
        tmp = 0
        while tmp < self.__nbr_originate_numbers__:
            self.__originating_numbers__[tmp] = {
                'idx': tmp,
                'number': originate_parameters_table[:phone_number_length],
                'status': None
            }
            originate_parameters_table = originate_parameters_table[
                phone_number_length:]
            tmp += 1

        ### Parse ORIGINATE_SHCEDULE_TBL ###
        primary_phone_number_idx = ord(originate_schedule_table[0]) & 7
        secondary_phone_number_idx = (
            ord(originate_schedule_table[0]) >> 4) & 7
        if primary_phone_number_idx < 7:
            self.__primary_phone_number_idx__ = primary_phone_number_idx
        if secondary_phone_number_idx < 7:
            self.__secondary_phone_number_idx__ = secondary_phone_number_idx

        ### Prase ANSWER_PARAMETERS_TBL ###
        if bit_rate_settings == 2:
            self.__answer_bit_rate__ = unpack(conn.c1219_endian + 'I',
                                              answer_parameters_table[0:4])[0]
        self.updateLastCallStatuses()
Пример #5
0
    def __init__(self, conn):
        """
		Initializes a new instance of the class and reads tables from the
		corresponding decades to populate information.

		@type conn: c1218.connection.Connection
		@param conn: The driver to be used for interacting with the
		necessary tables.
		"""
        self.conn = conn
        act_security_table = conn.get_table_data(ACT_SECURITY_LIMITING_TBL)
        security_table = conn.get_table_data(SECURITY_TBL)
        access_ctl_table = conn.get_table_data(ACCESS_CONTROL_TBL)
        try:
            key_table = conn.get_table_data(KEY_TBL)
        except C1218ReadTableError:
            key_table = None

        if len(act_security_table) < 6:
            raise C1219ParseError(
                'expected to read more data from ACT_SECURITY_LIMITING_TBL',
                ACT_SECURITY_LIMITING_TBL)

        ### Parse ACT_SECURITY_LIMITING_TBL ###
        self._nbr_passwords = act_security_table[0]
        self._password_len = act_security_table[1]
        self._nbr_keys = act_security_table[2]
        self._key_len = act_security_table[3]
        self._nbr_perm_used = struct.unpack(self.conn.c1219_endian + 'H',
                                            act_security_table[4:6])[0]

        ### Parse SECURITY_TBL ###
        if len(security_table) != (
            (self.nbr_passwords * self.password_len) + self.nbr_passwords):
            raise C1219ParseError(
                'expected to read more data from SECURITY_TBL', SECURITY_TBL)
        self._passwords = {}
        tmp = 0
        while tmp < self.nbr_passwords:
            self._passwords[tmp] = {
                'idx': tmp,
                'password': security_table[:self.password_len],
                'groups': security_table[self.password_len]
            }
            security_table = security_table[self.password_len + 1:]
            tmp += 1

        ### Parse ACCESS_CONTROL_TBL ###
        if len(access_ctl_table) != (self.nbr_perm_used * 4):
            raise C1219ParseError(
                'expected to read more data from ACCESS_CONTROL_TBL',
                ACCESS_CONTROL_TBL)
        self._table_permissions = {}
        self._procedure_permissions = {}
        tmp = 0
        while tmp < self.nbr_perm_used:
            (proc_nbr, std_vs_mfg, proc_flag, flag1, flag2,
             flag3) = get_table_idcb_field(self.conn.c1219_endian,
                                           access_ctl_table)
            if proc_flag:
                self._procedure_permissions[proc_nbr] = {
                    'idx': proc_nbr,
                    'mfg': std_vs_mfg,
                    'anyread': flag1,
                    'anywrite': flag2,
                    'read': access_ctl_table[2],
                    'write': access_ctl_table[3]
                }
            else:
                self._table_permissions[proc_nbr] = {
                    'idx': proc_nbr,
                    'mfg': std_vs_mfg,
                    'anyread': flag1,
                    'anywrite': flag2,
                    'read': access_ctl_table[2],
                    'write': access_ctl_table[3]
                }
            access_ctl_table = access_ctl_table[4:]
            tmp += 1

        ### Parse KEY_TBL ###
        self._keys = {}
        if key_table is not None:
            if len(key_table) != (self.nbr_keys * self.key_len):
                raise C1219ParseError(
                    'expected to read more data from KEY_TBL', KEY_TBL)
            tmp = 0
            while tmp < self.nbr_keys:
                self._keys[tmp] = key_table[:self.key_len]
                key_table = key_table[self.key_len:]
                tmp += 1
Пример #6
0
    def __init__(self, conn):
        """
		Initializes a new instance of the class and reads tables from the
		corresponding decades to populate information.

		@type conn: c1218.connection.Connection
		@param conn: The driver to be used for interacting with the
		necessary tables.
		"""
        self.conn = conn
        general_config_table = conn.get_table_data(GEN_CONFIG_TBL)
        general_mfg_table = conn.get_table_data(GENERAL_MFG_ID_TBL)
        try:
            mode_status_table = conn.get_table_data(ED_MODE_STATUS_TBL)
        except C1218ReadTableError:
            mode_status_table = None
        try:
            ident_table = conn.get_table_data(DEVICE_IDENT_TBL)
        except C1218ReadTableError:
            ident_table = None

        if len(general_config_table) < 19:
            raise C1219ParseError(
                'expected to read more data from GEN_CONFIG_TBL',
                GEN_CONFIG_TBL)
        if len(general_mfg_table) < 17:
            raise C1219ParseError(
                'expected to read more data from GENERAL_MFG_ID_TBL',
                GENERAL_MFG_ID_TBL)
        if mode_status_table and len(mode_status_table) < 5:
            raise C1219ParseError(
                'expected to read more data from ED_MODE_STATUS_TBL',
                ED_MODE_STATUS_TBL)

        ### Parse GEN_CONFIG_TBL ###
        self.__char_format__ = {
            1: 'ISO/IEC 646 (7-bit)',
            2: 'ISO 8859/1 (Latin 1)',
            3: 'UTF-8',
            4: 'UTF-16',
            5: 'UTF-32'
        }.get((ord(general_config_table[0]) & 14) >> 1) or 'Unknown'
        self.__nameplate_type__ = {
            0: 'Gas',
            1: 'Water',
            2: 'Electric'
        }.get(ord(general_config_table[7])) or 'Unknown'
        self.__id_form__ = ord(general_config_table[1]) & 32
        self.__std_version_no__ = ord(general_config_table[11])
        self.__std_revision_no__ = ord(general_config_table[12])
        self.__dim_std_tbls_used__ = ord(general_config_table[13])
        self.__dim_mfg_tbls_used__ = ord(general_config_table[14])
        self.__dim_std_proc_used__ = ord(general_config_table[15])
        self.__dim_mfg_proc_used__ = ord(general_config_table[16])

        self.__std_tbls_used__ = []
        tmp_data = general_config_table[19:]
        for p in xrange(self.__dim_std_tbls_used__):
            for i in xrange(7):
                if ord(tmp_data[p]) & (2**i):
                    self.__std_tbls_used__.append(i + (p * 8))

        self.__mfg_tbls_used__ = []
        tmp_data = tmp_data[self.__dim_std_tbls_used__:]
        for p in xrange(self.__dim_mfg_tbls_used__):
            for i in xrange(7):
                if ord(tmp_data[p]) & (2**i):
                    self.__mfg_tbls_used__.append(i + (p * 8))

        self.__std_proc_used__ = []
        tmp_data = tmp_data[self.__dim_mfg_tbls_used__:]
        for p in xrange(self.__dim_std_proc_used__):
            for i in xrange(7):
                if ord(tmp_data[p]) & (2**i):
                    self.__std_proc_used__.append(i + (p * 8))

        self.__mfg_proc_used__ = []
        tmp_data = tmp_data[self.__dim_std_proc_used__:]
        for p in xrange(self.__dim_mfg_proc_used__):
            for i in xrange(7):
                if ord(tmp_data[p]) & (2**i):
                    self.__mfg_proc_used__.append(i + (p * 8))

        ### Parse GENERAL_MFG_ID_TBL ###
        self.__manufacturer__ = general_mfg_table[0:4].rstrip()
        self.__ed_model__ = general_mfg_table[4:12].rstrip()
        self.__hw_version_no__ = ord(general_mfg_table[12])
        self.__hw_revision_no__ = ord(general_mfg_table[13])
        self.__fw_version_no__ = ord(general_mfg_table[14])
        self.__fw_revision_no__ = ord(general_mfg_table[15])
        if self.__id_form__ == 0:
            self.__mfg_serial_no__ = general_mfg_table[16:32].strip()
        else:
            self.__mfg_serial_no__ = general_mfg_table[16:24]

        ### Parse ED_MODE_STATUS_TBL ###
        if mode_status_table:
            self.__ed_mode__ = ord(mode_status_table[0])
            self.__std_status__ = struct.unpack(conn.c1219_endian + 'H',
                                                mode_status_table[1:3])[0]

        ### Parse DEVICE_IDENT_TBL ###
        if ident_table:
            if self.__id_form__ == 0 and len(ident_table) != 20:
                raise C1219ParseError(
                    'expected to read more data from DEVICE_IDENT_TBL',
                    DEVICE_IDENT_TBL)
            elif self.__id_form__ != 0 and len(ident_table) != 10:
                raise C1219ParseError(
                    'expected to read more data from DEVICE_IDENT_TBL',
                    DEVICE_IDENT_TBL)
            self.__device_id__ = ident_table.strip()