Tool to (re)configure the sysmoUSIM and sysmoISIM cards
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.7 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Commandline interface for sysmoUSIM-SJS1
  5. (C) 2017 by Sysmocom s.f.m.c. GmbH
  6. All Rights Reserved
  7. Author: Philipp Maier
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. import sys, getopt
  20. from utils import *
  21. from simcard import *
  22. from sysmo_usim_sjs1 import *
  23. from common import *
  24. class Application(Common):
  25. write_iccid = None
  26. write_sim_mode = None # True = USIM, False = classic SIM
  27. show_sim_mode = False
  28. write_iccid = None
  29. write_imsi = None
  30. # Automatically executed by superclass
  31. def _banner(self):
  32. print("sysmoUSIM-SJS1 parameterization tool")
  33. print("Copyright (c)2017-2019 Sysmocom s.f.m.c. GmbH")
  34. print("")
  35. # Automatically executed by superclass
  36. def _options(self, opts):
  37. for opt, arg in opts:
  38. if opt in ("-I", "--set-iccid"):
  39. self.write_iccid = asciihex_to_list(pad_asciihex(arg))
  40. elif opt in ("-u", "--usim"):
  41. self.write_sim_mode = True
  42. elif opt in ("-c", "--classic"):
  43. self.write_sim_mode = False
  44. elif opt in ("-m", "--mode"):
  45. self.show_sim_mode = True
  46. # Automatically executed by superclass when -h or --help is supplied as option
  47. def _helptext(self):
  48. print(" -I, --set-iccid ................ Set ICCID value")
  49. print(" -u, --usim ..................... Enable USIM mode")
  50. print(" -c, --classic .................. Disable USIM mode (make classic-sim)")
  51. print(" -m, --mode ..................... Display mode (classic-sim or USIM?)")
  52. print("")
  53. print(" For Option -T, the following algorithms are valid:")
  54. print('\n'.join([' %d %s' % entry for entry in sysmo_usim_algorithms]))
  55. print("")
  56. # Automatically executed by superclass before _execute() is called
  57. def _init(self):
  58. self.sim = Sysmo_usim_sjs1()
  59. # Automatically executed by superclass
  60. def _execute(self):
  61. if self.write_iccid:
  62. self.sim.write_iccid(self.write_iccid)
  63. if self.write_sim_mode != None:
  64. self.sim.write_sim_mode(self.write_sim_mode)
  65. if self.show_sim_mode:
  66. self.sim.show_sim_mode()
  67. def main(argv):
  68. Application(argv, "ucmI:", ["usim", "classic", "mode", "set-iccid="])
  69. if __name__ == "__main__":
  70. main(sys.argv[1:])