k2t.sh 991 B

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