From 808282c34749d3bb3e90225ba2c662eb24d9d532 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Tue, 6 Feb 2018 00:22:24 +0100 Subject: [PATCH] Moved device-specific settings to own class. Only used in tclcheck_allfull for now. --- tclcheck_allfull.py | 15 ++++------ tcllib/__init__.py | 2 +- tcllib/devices.py | 71 +++++++++++++++++++++++++++++++++++++++++++++ tcllib/tclcheck.py | 38 ++++++++++++++++-------- 4 files changed, 104 insertions(+), 22 deletions(-) create mode 100644 tcllib/devices.py diff --git a/tclcheck_allfull.py b/tclcheck_allfull.py index eb01dc7..201712d 100644 --- a/tclcheck_allfull.py +++ b/tclcheck_allfull.py @@ -13,12 +13,13 @@ import tcllib import tcllib.argparser from tcllib import ansi from tcllib import devlist +from tcllib.devices import DesktopDevice +dev = DesktopDevice() + fc = tcllib.FotaCheck() -fc.serid = "3531510" -fc.fv = "AAA000" -fc.mode = fc.MODE.FULL +fc.mode = fc.MODE.FULL # still needed to set User-Agent dpdesc = """ Checks for the latest FULL updates for all PRD numbers or only for @@ -28,10 +29,6 @@ dp = tcllib.argparser.DefaultParser(__file__, dpdesc) dp.add_argument("-p", "--prd", help="CU Reference # to filter scan results", dest="tocheck", nargs="?", default=None, metavar="PRD") args = dp.parse_args(sys.argv[1:]) -# CLTP = 10 (only show actual updates or HTTP 206) / 2010 (always show latest version for MODE.FULL) -#fc.cltp = fc.CLTP.MOBILE -fc.cltp = fc.CLTP.DESKTOP - prdcheck = "" if args.tocheck is None else args.tocheck print("Loading list of devices.") @@ -45,8 +42,8 @@ for prd, variant in prds.items(): if prdcheck in prd: try: fc.reset_session() - fc.curef = prd - check_xml = fc.do_check(max_tries=20) + dev.curef = prd + check_xml = fc.do_check(dev, max_tries=20) curef, fv, tv, fw_id, fileid, fn, fsize, fhash = fc.parse_check(check_xml) txt_tv = tv if tv != lastver: diff --git a/tcllib/__init__.py b/tcllib/__init__.py index cfe25ce..631b3e4 100644 --- a/tcllib/__init__.py +++ b/tcllib/__init__.py @@ -10,7 +10,7 @@ import enum import requests from . import (dumpmgr, servervote, tclcheck, - tclchecksum, tclencheader, tclrequest, xmltools) + tclchecksum, tclencheader, tclrequest) def default_enum(enumname, vardict, qualroot="tcllib.FotaCheck"): diff --git a/tcllib/devices.py b/tcllib/devices.py new file mode 100644 index 0000000..ea34419 --- /dev/null +++ b/tcllib/devices.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +"""Pseudo-devices for desktop/mobile requests""" + +class Device(): + CLTP_STATES = { + "MOBILE": 10, # only show actual newer versions or HTTP 206 + "DESKTOP": 2010, # always show latest version for FULL updates + } + MODE_STATES = {"OTA": 2, "FULL": 4} + CHNL_STATES = {"3G": 1, "WIFI": 2} + CKTP_STATES = {"AUTO": 1, "MANUAL": 2} + CKOT_STATES = {"ALL": 1, "AOTA_ONLY": 2, "FOTA_ONLY": 3} + + def __init__(self, curef, fwver): + self.curef = curef + self.imei = "" + self.osver = "7.1.1" + self.fwver = fwver + self.rtd = 0 + self.cltp = self.CLTP_STATES["DESKTOP"] + self.mode = self.MODE_STATES["FULL"] + self.type = "Firmware" + self.chnl = self.CHNL_STATES["WIFI"] + self.cktp = self.CKTP_STATES["MANUAL"] + self.ckot = self.CKOT_STATES["ALL"] + self.ua = "tcl" + + def is_rooted(self): + return (self.rtd == 1) + + def set_rooted(self, new_state: bool): + if new_state: + self.rtd = 1 + else: + self.rtd = 0 + + def set_cltp(self, new_cltp: str): + # (Numerical CLTPs can be set by direct assigns.) + # Throws exception when invalid cltp given: + self.cltp = self.CLTP_STATES[new_cltp] + + def set_mode(self, new_mode: str): + # (Numerical MODEs can be set by direct assigns.) + # Throws exception when invalid mode given: + self.mode = self.MODE_STATES[new_mode] + + def set_chnl(self, new_chnl: str): + # (Numerical CHNLs can be set by direct assigns.) + # Throws exception when invalid mode given: + self.chnl = self.CHNL_STATES[new_chnl] + + def set_ckot(self, new_ckot: str): + # (Numerical CKOTs can be set by direct assigns.) + # Throws exception when invalid mode given: + self.ckot = self.CKOT_STATES[new_ckot] + +class MobileDevice(Device): + def __init__(self, curef="PRD-63117-011", fwver="AAO472"): + super().__init__(curef, fwver) + self.imei = "3531510" + self.set_cltp("MOBILE") + self.set_mode("OTA") + self.ua = "com.tcl.fota/5.1.0.2.0029.0, Android" + +class DesktopDevice(Device): + def __init__(self, curef="PRD-63117-011", fwver="AAA000"): + super().__init__(curef, fwver) + self.imei = "543212345000000" + self.set_cltp("DESKTOP") + self.set_mode("FULL") diff --git a/tcllib/tclcheck.py b/tcllib/tclcheck.py index a3156e7..8358ec4 100644 --- a/tcllib/tclcheck.py +++ b/tcllib/tclcheck.py @@ -14,22 +14,36 @@ from defusedxml import ElementTree class TclCheckMixin: """A mixin component for TCL's update request API.""" - def do_check(self, https=True, timeout=10, max_tries=5): + def do_check(self, device=None, https=True, timeout=10, max_tries=5): """Perform update request with given parameters.""" protocol = "https://" if https else "http://" url = protocol + self.g2master + "/check.php" params = OrderedDict() - params["id"] = self.serid - params["curef"] = self.curef - params["fv"] = self.fv - params["mode"] = self.mode.value - params["type"] = self.ftype - params["cltp"] = self.cltp.value - params["cktp"] = self.cktp.value - params["rtd"] = self.rtd.value - params["chnl"] = self.chnl.value - #params["osvs"] = self.osvs - #params["ckot"] = self.ckot.value + if device: + # Need to support both ways for now + params["id"] = device.imei + params["curef"] = device.curef + params["fv"] = device.fwver + params["mode"] = device.mode + params["type"] = device.type + params["cltp"] = device.cltp + params["cktp"] = device.cktp + params["rtd"] = device.rtd + params["chnl"] = device.chnl + #params["osvs"] = device.osvs + #params["ckot"] = device.ckot + else: + params["id"] = self.serid + params["curef"] = self.curef + params["fv"] = self.fv + params["mode"] = self.mode.value + params["type"] = self.ftype + params["cltp"] = self.cltp.value + params["cktp"] = self.cktp.value + params["rtd"] = self.rtd.value + params["chnl"] = self.chnl.value + #params["osvs"] = self.osvs + #params["ckot"] = self.ckot.value last_response = None for _ in range(0, max_tries):