_DEFAULT_5G_BANDS="1 3 5 7 8 20 28 38 40 41 75 76 77 78"
_DEFAULT_LTE_BANDS="1 3 5 7 8 20 28 32 38 40 41 42 43"

getinfo() {
  O=$(sms_tool -d $_DEVICE at "AT+CGMM?")
  _NAME="Fibocom $(echo "$O" | awk -F[:,] '/^\+CGMM:/{gsub("\"","");print $2}' | xargs)"
  echo "$_NAME"
}

getsupportedbands() {
    echo "$_DEFAULT_LTE_BANDS"
}

getbands() {
    O=$(sms_tool -d $_DEVICE at "AT+GTACT?")
    BANDS=$(echo "$O" | awk -F: '/^\+GTACT:/{gsub(","," ");print $2}')
    for BAND in $BANDS; do
        if [ $BAND -gt 100 ] && [ $BAND -lt 200 ]; then
            echo -n "$((BAND - 100)) "
        fi
    done
    echo ""
}

setbands() {
    BANDS="$1"

    T=""
    if [ "$BANDS" = "default" ]; then
        T="0"
    else
        for BAND in $BANDS; do
            case $BAND in
                ''|*[!0-9]*) continue ;;
            esac
            [ -n "$T" ] && T="${T},"
            T="${T}$((BAND + 100))"
        done
    fi

    if [ -n "$T" ]; then
        O=$(sms_tool -d $_DEVICE at "AT+GTACT?")
        MODE=$(echo "$O" | awk -F[:,] '/\+GTACT:/{print $2","$3","$4}'| xargs)
        sms_tool -d $_DEVICE at "AT+GTACT=$MODE,$T"
    fi
}

getsupportedbands5gsa() {
    echo "$_DEFAULT_5G_BANDS"
}

getsupportedbands5gnsa() {
    echo "$_DEFAULT_5G_BANDS"
}

getbands5gsa() {

    O=$(sms_tool -d $_DEVICE at "AT+GTACT?")
    BANDS=$(echo "$O" | awk -F: '/^\+GTACT:/{gsub(","," ");print $2}')
    for BAND in $BANDS; do
        if [ $BAND -gt 500 ] && [ $BAND -lt 5100 ]; then
            echo -n "$(echo "$BAND" | sed 's/^50//g') "
        fi
    done
    echo ""
}

getbands5gnsa() {

    O=$(sms_tool -d $_DEVICE at "AT+GTACT?")
    BANDS=$(echo "$O" | awk -F: '/^\+GTACT:/{gsub(","," ");print $2}')
    for BAND in $BANDS; do
        if [ $BAND -gt 500 ] && [ $BAND -lt 5100 ]; then
            echo -n "$(echo "$BAND" | sed 's/^50//g') "
        fi
    done
    echo ""
}


setbands5gsa() {
    BANDS="$1"

    T=""
    if [ "$BANDS" = "default" ]; then
        T="0"
    else
        for BAND in $BANDS; do
            case $BAND in
                ''|*[!0-9]*) continue ;;
            esac
            [ -n "$T" ] && T="${T},"
            T="${T}50${BAND}"
        done
    fi

    if [ -n "$T" ]; then
        O=$(sms_tool -d $_DEVICE at "AT+GTACT?")
        MODE=$(echo "$O" | awk -F[:,] '/\+GTACT:/{print $2","$3","$4}'| xargs)
        sms_tool -d $_DEVICE at "AT+GTACT=$MODE,$T"
    fi
}

setbands5gnsa() {
    BANDS="$1"

    T=""
    if [ "$BANDS" = "default" ]; then
        T="0"
    else
        for BAND in $BANDS; do
            case $BAND in
                ''|*[!0-9]*) continue ;;
            esac
            [ -n "$T" ] && T="${T},"
            T="${T}50${BAND}"
        done
    fi

    if [ -n "$T" ]; then
        O=$(sms_tool -d $_DEVICE at "AT+GTACT?")
        MODE=$(echo "$O" | awk -F[:,] '/\+GTACT:/{print $2","$3","$4}'| xargs)
        sms_tool -d $_DEVICE at "AT+GTACT=$MODE,$T"
    fi
}

