summaryrefslogtreecommitdiff
path: root/recipes-core/multitech/cell-radio-fwswitch/cell-radio-fwswitch.init
blob: 82b5cb59f244be308fd8c2d11bf4e94fdf971bbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

# no firmware switch by default
ENABLED="no"
# radio come up timeout
TIMEOUT=15
# default radio firmware image id
FWIMAGE="0"

[ -r /etc/default/cell-radio-fwswitch ] && source /etc/default/cell-radio-fwswitch
[ "$ENABLED" == "yes" ] || exit 0

function start() {
  FWACTIVE=$(radio-query --active-firmware)
  if [[ $? != 0  || x"$FWACTIVE" == x"" ]]; then
    # radio does not support firmware switching.
    exit 0
  fi

  FWSWITCH=$(curl -s 127.0.0.1/api/ppp/modem/fwSwitch | jsparser -p /result/)
  if [[ x"$FWSWITCH" == x"" ]]; then
      echo "Failed to obtain the radio firmware image id to use."
      exit 1
  fi

  if [[ "$FWSWITCH" == "att"  ]]; then
      FWIMAGE="0"
  elif [[ "$FWSWITCH" == "vz"  ]]; then
      FWIMAGE="1"
  else
      # autodetect
      ICCID=$(radio-query --iccid)
      if [ $? -ne 0 ]; then
          exit 0
      fi
      if [[ "$ICCID" =~ ^89148.* ]]; then
          #
          # Switch to FW image #1 for Verizon SIMs
          #
          FWIMAGE="1"
      fi
  fi

  cell-radio-fwswitch $FWIMAGE $TIMEOUT
}

case $1 in
  start)
    start
    ;;

  *)
    echo "Usage: $0 {start}"
    exit 2
    ;;
esac