k2t.sh 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #
  2. # Copyright (C) 2018 Weijie Gao <[email protected]>
  3. #
  4. # Helper function to extract mac addresses from mtd part for Phicomm K2T
  5. #
  6. . /lib/functions.sh
  7. . /lib/functions/system.sh
  8. . /usr/share/libubox/jshn.sh
  9. k2t_config_load() {
  10. local mtd_blk=$(find_mtd_part config)
  11. if [ -z "$mtd_blk" ]; then
  12. echo "k2t_config_load: no mtd part named config" >&2
  13. exit 1
  14. fi
  15. local json_size=$(dd if=$mtd_blk bs=1 count=8 2>/dev/null)
  16. json_size="0x$json_size"
  17. json_size=$((json_size))
  18. if [ "$?" -ne 0 ]; then
  19. echo "k2t_config_load: invalid json data size" >&2
  20. exit 2
  21. fi
  22. if [ "$json_size" -eq 0 ]; then
  23. echo "k2t_config_load: empty json data" >&2
  24. exit 3
  25. fi
  26. local json_data=$(dd if=$mtd_blk bs=1 skip=8 count=$json_size 2>/dev/null)
  27. json_load "$json_data"
  28. }
  29. k2t_get_mac() {
  30. local old_ns
  31. json_set_namespace "k2t" old_ns
  32. if k2t_config_load; then
  33. json_select "this_dev_info"
  34. json_get_var val "$1"
  35. json_select ..
  36. fi
  37. json_set_namespace old_ns
  38. echo $val
  39. }