Skip to content

Instantly share code, notes, and snippets.

@plugnburn
Last active December 16, 2024 05:17
Show Gist options
  • Save plugnburn/5b2582be521944f739e1 to your computer and use it in GitHub Desktop.
Save plugnburn/5b2582be521944f739e1 to your computer and use it in GitHub Desktop.
NokiaTool - simple interface Bash script for MediaTek-based Nokia simple phones

NokiaTool: control MediaTek-based Nokia phones from your PC

Overview

NokiaTool is a simple Bash script (nokiatool.sh) that allows you to use an undocumented serial connection in USB-enabled MediaTek-based Nokia feature phones manufactured by Microsoft (even the most basic ones, like the new 105) in order to control them from your PC.

This project is an ongoing work and uses only some bits and pieces of information about the phone internals available to the public, so under any circumstances don't consider it stable or a replacement for official tools if any are present.

P.S. Never try to run this for Nokia 105-2019 and 110-2019. They are based on Spreadtrum SC6531EFM, not MediaTek.

Configuration and running

Dependencies: stty, grep, iconv, od, sed, tr, cut. Most probably they are already present in your distribution.

First of all, you have to make sure that you have the suitable driver initialization command (DRIVERINIT variable) in the script. If you have Nokia 105 or 130, you can leave it as is, otherwise you'll probably have to change vendor/product ID according to actual device (or leave this command empty altogether).

Second, you may have to adjust the actual serial port capable of receiving AT commands (MODEM variable). For example, Nokia 105 DS opens two ports, and the second one (/dev/ttyUSB1 in my case) is the right one to connect. Your mileage may vary.

After that, just make the script executable (via chmod +x) and you are ready to go.

NokiaTool functionality is divided into subcommands. Each of them is described in corresponding section. If you're not running the script under root privileges but any useful command (not in the help section), it will ask you for your sudo password in order to authorize modem device access. This is completely safe because the only root-enabled operation is writing into /dev/ttyUSBx or whatever character device file you choose in the MODEM variable.

Choosing a SIM for further operation

If you have a dual-SIM model with 2 active SIM cards, all operations are performed via SIM 1 by default. If you need to select the second SIM to dial a number or send SMS via NokiaTool , please run:

nokiatool.sh sim select-second

And if you need to return to the first SIM, just run:

nokiatool.sh sim select-first

Note that active SIM is reset to SIM 1 after each phone reboot.

Main functions

The simplest NokiaTool commands are:

  • Dial a number: nokiatool.sh dial <number>, e.g. nokiatool.sh dial 5433
  • Answer the call: nokiatool.sh pickup
  • End the call: nokiatool.sh hangup
  • Send an SMS message (no concatenated messages suport for now: Unicode is supported but limited to 70 characters, Latin messages can use 160 characters, quotes must be escaped properly): nokiatool.sh sms <number> <message>, e.g. nokiatool.sh sms +18003733411 hello dudes!
  • Write an SMS draft (all the same limitations apply) and save it into the phone: nokiatool.sh draft <message>, e.g. nokiatool.sh draft Don\\\'t forget to buy some milk
  • Send a Flash SMS (also known as Class 0 SMS - an SMS that's displayed immediately and doesn't get saved into the inbox by default) up to 70 characters long (Unicode only): nokiatool.sh flash-sms <number> <message>, e.g. nokiatool.sh flash-sms +18003733411 You won\\\'t find me at the party
  • Reboot the phone: nokiatool.sh reboot

SIM control

Besides sim select-first and sim select-second, NokiaTool provides some more commands to control SIM activity:

  • nokiatool.sh sim off - turn off both SIMs (flight mode!)
  • nokiatool.sh sim current-off - turn off current selected SIM
  • nokiatool.sh sim first - activate SIM 1 only
  • nokiatool.sh sim second - activate SIM 2 only (for dual-SIM models)
  • nokiatool.sh sim both - activate both SIMs

Phonebook and call logs

Reading (export)

NokiaTool allows you to easily export any section of your phonebook or call logs into CSV format so that you can easily view your contacts on a PC or transfer them to another device. It's done with nokiatool.sh phonebook-read subcommand. You can view contacts in the console, redirect the output into a file (it's separated from info messages) or even pipe it to other program for processing. For example, nokiatool.sh phonebook-read phone > phone.csv command exports the entire device phonebook into the phone.csv file.

The following reading modes are supported for different phonebook parts:

  • nokiatool.sh phonebook-read phone - view/export device phonebook;
  • nokiatool.sh phonebook-read sim - view/export currently selected SIM card phonebook;
  • nokiatool.sh phonebook-read own - view/export own number list of current SIM;
  • nokiatool.sh phonebook-read fdn - view/export FDN number list.

All phonebook entries are exported in the following CSV line format: <index>,"<name>",<number>. You can also omit indexes by passing short as the last parameter, for example, nokiatool.sh phonebook-read sim short. This way only "<name>",<number> will be present in each CSV line.

The following reading modes are supported for different call logs:

  • nokiatool.sh phonebook-read last - view/export last dialed numbers;
  • nokiatool.sh phonebook-read outgoing - view/export all dialed numbers;
  • nokiatool.sh phonebook-read received - view/export all received calls;
  • nokiatool.sh phonebook-read missed - view/export all missed calls.

All call log entries are exported in the following CSV line format: <index>,<number>,"<date>","<time>". You can also omit indexes by passing short as the last parameter. Contact names are not exported due to encoding issues present in internal call log representation of the device. But this should not be a problem: once you have exported the phonebooks, you can match the necessary names using other tools.

Writing (individual)

To create, update and delete individual phonebook entries, the following commands are supported for each <type>, where <type> can be either phone (device memory) or sim (current selected SIM card memory):

  • nokiatool.sh phonebook-create <type> <number> <name> - create a new phonebook entry;
  • nokiatool.sh phonebook-update <type> <index> <number> <name> - update an existing phonebook entry by its index;
  • nokiatool.sh phonebook-delete <type> <index> - erase an existing phonebook entry by its index.

For example: nokiatool.sh phonebook-create sim 5433 My service will write a local number 5433 to current SIM card memory, and nokiatool.sh phonebook-update phone 23 +1234567890 My American Friend will update the cell #23 with an international number on the phone memory.

When creating or updating any entry, contact name can be specified without quotes but all usual escaping rules apply.

Bulk import

NokiaTool finally gets support for bulk contact import from CSV format. The command is the following:

nokiatool.sh phonebook-import <type> < file.csv

where <type> can be either phone (device memory) or sim (current selected SIM card memory).

Both short and full (with indexes) CSV formats are recognized. If indexes are present, NokiaTool will replace the phonebook entries present in those cells.

You can also pipe other programs stdout or create/modify entries by typing them directly in the console (end with Ctrl+D sequence) instead of specifying the CSV file to read (with < file.csv).

Note that bulk phonebook export/import are the most resource-heavy operations of NokiaTool so you may have to wait some time to get the job done.

Keypad emulation

New Nokias, just like any other MediaTek-based phones, provide complete support for keypad entry emulation. NokiaTool encapsulates this feature into a single nokiatool.sh keypad "<keystring>" command. The <keystring> can consist of everything you can find on the physical Nokia keypad: digits, * and # characters and all control keys that are encoded in a special way:

  • Softkeys: [ - left, m - central (menu), ] - right
  • Operating keys: s - send (call) key, e - hangup key
  • Arrows: < - left, > - right, ^ - up, v - down

You can also get the above information by running nokiatool.sh keypad-help.

For example, the command nokiatool.sh keypad "e[*111#svs" will perform the following actions on a Nokia 105 DS: unlock the keypad, dial the *111# USSD code, press "Send" key to make the call, select the second SIM by pressing "Down" and actually send the USSD code by pressing "Send" again. Actually you can emulate any actions a normal user would perform on the phone.

Expert mode functions

The following commands belong to the expert section and are meant to perform potentially dangerous operations, so you really must know what you are doing, and proceed at your own risk only.

  • GSM band selection: nokiatool.sh expert band <900|euro|amer|auto> - support heavily depends on the model and region, for Nokia 105 or 130 only nokiatool.sh expert band 900 (select GSM900 mode only) makes a real difference from other supported modes (euro or auto)
  • Backlight mode: nokiatool.sh expert backlight <constant|normal> - turn the display backlight constantly on or return it to the normal mode
  • Audio playback test: nokiatool expert audiotest <start|stop> <sound id> <style> [duration] - MediaTek audio test (style can vary from 0 to 3)
  • Audio loopback test: nokiatool.sh expert loopback <on|off> - whatever you say into the microphone is played in the speaker
  • Audio routing: nokiatool.sh expert audioroute <normal|headset|speaker> - force routing all audio to speaker or headset or return to the normal mode

Raw AT control

Though this way is even more dangerous than expert section commands and it's advisable to use full-featured terminal application like Minicom for this, you can also send any raw AT command with:

nokiatool.sh sendATcmd '<your_cmd>'

Quotes (either single or double, single preferred) around <your_cmd> are mandatory. CR and/or LF characters are not needed (they are inserted automatically, you don't have to worry about line endings). Note that this command is write-only, i.e. it will not read any response from the device. So use it only if you're absolutely sure about the result.

For example, you can also reboot your phone with a raw AT command in such a way: nokiatool.sh sendATcmd 'AT+CFUN=1,1'

If you send an AT command after which the device awaits some raw text data following (for example, AT+CMGW) using this method, you'll have to complete the command sequence using a terminal application (like Minicom) or use sendTextData subcommand as the following:

nokiatool.sh sendTextData '<your text>'

Quotes around <your text> are mandatory here too. So, for example, you can save a simple Latin-based SMS draft with the following sequence:

nokiatool.sh sendATcmd 'AT+CMGF=1'
nokiatool.sh sendATcmd 'AT+CMGW'
nokiatool.sh sendTextData "Don\'t forget to buy some milk"

But again, be very careful!

Future development plans

For sooner development

  • Information commands
  • Ability to use a number from CSV phonebook dump for dialing/SMS

For far-future development

  • Concatenated SMS
  • GUI frontend

Will never be implemented (due to lack of device support)

  • File system interaction (AT+ESUO=3 and respective file system commands are not supported)
  • GPRS modem functionality (AT+CG commands are not supported at all)
  • SMS listings (AT+CMGL is not supported)
  • USSD queries (AT+CUSD / AT+ECUSD are not supported)
  • Phonebook immediate on-device search (AT+CPBF isn't supported)
#!/bin/bash
# NokiaTool - control MediaTek-based Nokia phones from your PC
# (c) Suborg 2016
# Released into public domain since 2023
# change two following lines for your specific device, mine are for MediaTek-based Nokia 130 and new 105
MODEM='/dev/ttyUSB1' # Nokia opens two serial ports, we need the second one to send control commands
DRIVERINIT='modprobe usbserial vendor=0x0421 product=0x069a' # init Nokia usb2serial driver (not needed for some models if they are autodetected)
# modem interaction API
CR="$(echo -e '\r')"
FD=8
function prepareModem {
stty -F $MODEM -parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase -tostop -echoprt -echoctl -echoke -extproc
}
function sendATcmd {
local cmd="$1"
echo -ne "$cmd$CR" >&${FD}
sleep 1
}
function sendTextData {
local text="$*"
echo -ne "$text\x1A" >&${FD}
sleep 1
}
function readResponse {
expectedString="$1"
timeout="$2"
[[ -z $timeout ]] && timeout=1
respString=''
while read -d "$CR" -u$FD -t $timeout -s -r RESP; do
if [[ $? -ge 128 ]] ; then return 1 ; fi
if [[ $RESP == "ERROR" ]] ; then return 1; fi
[[ $RESP == ${expectedString}* ]] && respString="$respString$RESP\n"
done
echo -ne "$respString"
return 0
}
# encoder
function utf8topdu {
echo -n "$*"|iconv -f utf-8 -t ucs-2be|od -t x1 -An |tr -d '\n '|tr 'a-f' 'A-F'
}
# decoder
function pdutoutf8 {
echo -ne "$(echo -n $* | sed -e 's/../\\x&/g')" | iconv -f ucs-2be -t utf-8
}
# print info messages
function printinfo {
echo "$@" 1>&2;
}
# encode PDU: encodePDU <destination number> <normal|flash> text
function encodePDU {
local num="$(echo $1|sed 's/[^0-9]*//g')"
local type="$2"
shift 2
local text="$*"
local numlen=${#num}
[[ $((numlen%2)) -eq 1 ]] && num="${num}F"
local PDU="003100$(printf '%02X' $numlen)91$(echo -n $num|iconv -f utf-16le -t utf-16be)00"
if [[ $type == 'flash' ]]; then
PDU="${PDU}1"
else
PDU="${PDU}0"
fi
PDU="${PDU}8FF$(printf '%02X' $((${#text}*2)))$(utf8topdu $text)"
echo -n "$PDU"
}
function encodeDraftPDU {
local type="$1"
shift 1
local text="$*"
local typevar=0
[[ $type == 'flash' ]] && typevar=1
echo -n "001100009100${typevar}8AA$(printf '%02X' $((${#text}*2)))$(utf8topdu $text)"
}
# Send SMS: nokiatool sms number message
# number in international format, message can be passed with no quotes
# Unicode messages mustn't exceed 70 characters
function sms {
sendATcmd 'ATZ'
local number="$1"
shift 1
local text="$*"
printinfo "Sending SMS..."
if [[ -n "$(echo $text|grep -P '[^\x00-\x7f]')" ]]; then #unicode detected
local PDU="$(encodePDU $number normal $text)"
sendATcmd 'AT+CMGF=0'
sendATcmd "AT+CMGS=$(( ${#PDU}/2-1 ))"
sendTextData "$PDU"
else #latin encoding detected
sendATcmd 'AT+CMGF=1'
sendATcmd "AT+CMGS=\"$number\""
sendTextData "$text"
fi
local resp=$(readResponse '+CMGS')
if [[ $? -eq 0 ]]; then
printinfo "SMS sent"
else
printinfo "SMS error occurred, please try again"
fi
}
# Send Flash SMS: nokiatool flash-sms number message
# number in international format, message can be passed with no quotes
# Unicode only, all messages mustn't exceed 70 characters
function flash-sms {
sendATcmd 'ATZ'
local number="$1"
shift 1
local text="$*"
printinfo "Sending Flash SMS..."
local PDU="$(encodePDU $number flash $text)"
sendATcmd 'AT+CMGF=0'
sendATcmd "AT+CMGS=$(( ${#PDU}/2-1 ))"
sendTextData "$PDU"
local resp=$(readResponse '+CMGS')
if [[ $? -eq 0 ]]; then
printinfo "Flash SMS sent"
else
printinfo "SMS error occurred, please try again"
fi
}
# Save SMS draft (as a note): nokiatool draft message
# message can be passed with no quotes
# Unicode messages mustn't exceed 70 characters
function draft {
sendATcmd 'ATZ'
local text="$*"
printinfo "Saving draft to SMS memory..."
if [[ -n "$(echo $text|grep -P '[^\x00-\x7f]')" ]]; then #unicode detected
sendATcmd 'AT+CMGF=0'
local PDU="$(encodeDraftPDU normal $text)"
sendATcmd "AT+CMGW=$(( ${#PDU}/2-1 )),7"
sendTextData "$PDU"
else #latin encoding detected
sendATcmd 'AT+CMGF=1'
sendATcmd 'AT+CMGW'
sendTextData "$text"
fi
local resp=$(readResponse '+CMGW')
if [[ $? -eq 0 ]]; then
printinfo "Draft saved"
else
printinfo "Saving error occurred, please try again"
fi
}
# Reboot the phone
function reboot {
sendATcmd 'AT+CFUN=1,1'
printinfo "Phone rebooted"
}
# Dial a number: nokiatool dial 466
function dial {
sendATcmd 'ATZ'
local num="$1"
sendATcmd "ATD${num};"
printinfo "Number $num dialed"
}
# Answer a call
function pickup {
sendATcmd 'ATA'
printinfo "Call answered"
}
# Hangup active call
function hangup {
sendATcmd 'AT+CHUP'
printinfo "Hangup"
}
# SIM related functions
function sim {
local arg="$1"
case "$arg" in
off)
sendATcmd 'AT+CFUN=4,0' #could also use AT+EFUN=0 but AT+CFUN=4,0 is better documented
printinfo "Flight mode active"
;;
current-off)
sendATcmd 'AT+CFUN=0,0'
printinfo "Current selected SIM card disabled"
;;
first)
sendATcmd 'AT+EFUN=1'
printinfo "First SIM only active"
;;
second)
sendATcmd 'AT+EFUN=2'
printinfo "Second SIM only active"
;;
both)
sendATcmd 'AT+EFUN=3'
printinfo "Both SIMs active"
;;
select-first)
sendATcmd 'AT+ESUO=4'
printinfo "First SIM selected for terminal operations"
;;
select-second)
sendATcmd 'AT+ESUO=5'
printinfo "Second SIM selected for terminal operations"
;;
esac
}
# keypad emulation
function keypad {
local sequence="$*"
sendATcmd "AT+CKPD=\"$sequence\""
printinfo "Keypad sequence sent"
}
function keypad-help {
printinfo 'Special characters for "nokiatool keypad" command:'
printinfo 'Softkeys: [ - left, m - central (menu), ] - right'
printinfo 'Operating keys: s - send (call) key, e - hangup key'
printinfo 'Arrows: < - left, > - right, ^ - up, v - down'
}
# expert mode functions (run them only if you REALLY know what you're doing!)
function expert {
local arg="$1"
local arg2="$2"
case "$arg" in
band)
case "$arg2" in
900)
sendATcmd 'AT+EPBSE=2,0'
printinfo 'GSM900-only mode selected if supported'
;;
euro)
sendATcmd 'AT+EPBSE=10,1'
printinfo 'European GSM bands (900/1800) selected if supported'
;;
amer)
sendATcmd 'AT+EPBSE=144,0'
printinfo 'American GSM bands (850/1900) selected if supported'
;;
auto)
sendATcmd 'AT+EPBSE=255,65535'
printinfo 'Bands selected automatically'
;;
esac
;;
loopback)
case "$arg2" in
on)
sendATcmd 'AT+EALT=1'
printinfo 'Loopback test mode on'
;;
off)
sendATcmd 'AT+EALT=0'
printinfo 'Loopback test mode off'
;;
esac
;;
audioroute)
case "$arg2" in
speaker)
sendATcmd 'AT+ESAM=2'
printinfo 'Audio routed to speaker only'
;;
headset)
sendATcmd 'AT+ESAM=1'
printinfo 'Audio routed to headset only'
;;
normal)
sendATcmd 'AT+ESAM=0'
printinfo 'Audio routed in normal mode'
;;
esac
;;
backlight)
case "$arg2" in
constant)
sendATcmd 'AT+ELSM=0'
printinfo 'Switched backlight to constant-on mode'
;;
normal)
sendATcmd 'AT+ELSM=1'
printinfo 'Switched backlight to normal mode'
;;
esac
;;
audiotest)
case "$arg2" in
start)
id="$3"
style="$4"
duration="$5"
finalcmd="AT+CASP=1,$id,$style"
if [[ "$duration" ]]; then
finalcmd="$finalcmd,$duration"
fi
sendATcmd "$finalcmd"
printinfo "Started sound with ID $id"
;;
stop)
id="$3"
sendATcmd "AT+CASP=2,$id"
printinfo "Stopped sound with ID $id"
;;
esac
;;
esac
}
#phonebook manipulation
function phonebook-type-convert {
case "$1" in
sim) #current SIM phonebook
echo 'SM'
;;
phone) #device phonebook
echo 'ME'
;;
outgoing) #outgoing call log
echo 'DC'
;;
last) #last dial call log
echo 'LD'
;;
missed) #missed incoming call log
echo 'MC'
;;
received) #received incoming call log
echo 'RC'
;;
fdn) #FDN number list
echo 'FD'
;;
own) #own number list
echo 'ON'
;;
esac
}
function phonebook-read {
local type="$(phonebook-type-convert $1)"
local omit="$2"
sendATcmd 'ATZ'
sendATcmd 'AT+CSCS="UCS2"'
sendATcmd "AT+CPBS=\"$type\""
printinfo -e "Scanning entries (may take some time)...\n"
local rangeArg=''
until [[ -n "$rangeArg" ]]; do
sendATcmd 'AT+CPBR=?'
rangeArg=$(readResponse '+CPBR'|grep -Po '\(.*\)'|tr -d '()'|tr - ,)
done
sendATcmd "AT+CPBR=${rangeArg}"
local rawResponse="$(readResponse '+CPBR')"
local IFS=$'\n'
if [[ $type == 'SM' || $type == 'ME' || $type == 'ON' || $type == 'FD' ]]; then
for entry in $rawResponse; do
local localEntry=$(echo $entry|tr -d ',"')
local index=$(echo $localEntry|cut -d ' ' -f 2)
local phone=$(echo $localEntry|cut -d ' ' -f 3)
local numtype=$(echo $localEntry|cut -d ' ' -f 4)
local name=$(pdutoutf8 $(echo $localEntry|cut -d ' ' -f 5)|sed 's/\"/""/g')
[[ $numtype == "145" ]] && phone="+$phone"
if [[ $omit == "short" ]]; then
echo -e "\"${name}\",$phone"
else
echo -e "$index,\"${name}\",$phone"
fi
done
else
for entry in $rawResponse; do
local localEntry=$(echo $entry|sed 's/\+CPBR:\ //g'|tr -d '"')
local index=$(echo $localEntry|cut -d ',' -f 1)
local phone=$(echo $localEntry|cut -d ',' -f 2)
local numtype=$(echo $localEntry|cut -d ',' -f 3)
local date=$(echo $localEntry|cut -d ',' -f 5)
local time=$(echo $localEntry|cut -d ',' -f 6)
[[ $numtype == "145" ]] && phone="+$phone"
if [[ $omit == "short" ]]; then
echo -e "$phone,\"${date}\",\"${time}\""
else
echo -e "$index,$phone,\"${date}\",\"${time}\""
fi
done
fi
printinfo -e "\nDone"
}
# phonebook modification commands
function phonebook-create {
local type="$(phonebook-type-convert $1)"
local number="$2"
shift 2
local name="$(utf8topdu $*)"
local numtype=129
if [[ $number == "+"* ]]; then
numtype=145
number="${number:1}"
fi
sendATcmd 'AT+CSCS="UCS2"'
sendATcmd "AT+CPBS=\"$type\""
sendATcmd "AT+CPBW=,\"${number}\",$numtype,\"${name}\""
printinfo "New entry written to $type memory"
}
function phonebook-update {
local type="$(phonebook-type-convert $1)"
local index="$2"
local number="$3"
shift 3
local name="$(utf8topdu $*)"
local numtype=129
if [[ $number == "+"* ]]; then
numtype=145
number="${number:1}"
fi
sendATcmd 'AT+CSCS="UCS2"'
sendATcmd "AT+CPBS=\"$type\""
sendATcmd "AT+CPBW=$index,\"${number}\",$numtype,\"${name}\""
printinfo "Entry $index updated in $type memory"
}
function phonebook-delete {
local type="$(phonebook-type-convert $1)"
local index="$2"
sendATcmd "AT+CPBS=\"$type\""
sendATcmd "AT+CPBW=$index"
printinfo "Entry $index deleted from $type memory"
}
# import command: replaces when indexes present, writes to new cells when they are omitted (short format)
# accepts phonebook type (sim or phone)
# csv is read from stdin line-by-line (you can redirect a file with e.g. nokiatool.sh phonebook-import phone < phones.csv)
function phonebook-import {
local type="$(phonebook-type-convert $1)"
local count=0
printinfo "Importing contacts (please be patient)..."
sendATcmd 'AT+CSCS="UCS2"'
sendATcmd "AT+CPBS=\"$type\""
while read csvline; do
if [[ ! "$csvline" =~ ^[0-9]+,.* ]]; then
csvline=",$csvline"
fi
local index=$(echo -n "$csvline"|cut -d ',' -f 1)
local number=$(echo -n "$csvline"|rev|cut -d ',' -f 1|rev)
local name=$(echo -n "$csvline"|cut --complement -d ',' -f 1|rev|cut --complement -d ',' -f 1|rev)
[[ $index == '"'* && $index == *'"' ]] && index="${index:1:-1}"
[[ $number == '"'* && $number == *'"' ]] && number="${number:1:-1}"
[[ $name == '"'* && $name == *'"' ]] && name="${name:1:-1}"
name="$(echo -n $name| sed 's/\"\"/\"/g')"
local numtype=129
if [[ $number == "+"* ]]; then
numtype=145
number="${number:1}"
fi
sendATcmd "AT+CPBW=$index,\"${number}\",$numtype,\"$(utf8topdu $name)\""
count=$(( $count + 1 ))
done
printinfo "$count contacts imported into $type memory"
}
# actual command runner
function suexecWrap {
printinfo "Connecting to device..."
cmd="$1"
shift 1
local args=$*
$DRIVERINIT
if [[ ! -c $MODEM ]]; then
printinfo "Device connection failed!"
exit 1
fi
printinfo ''
prepareModem
eval "exec ${FD}<>$MODEM"
$cmd $args
eval "exec ${FD}<&-"
eval "exec ${FD}>&-"
}
if [[ "$1" == "help" ]]; then
${2}-help
exit 1
fi
CURSCRIPT="$(readlink -f $0)"
ARGS=$*
if [[ "$EUID" -ne 0 ]]; then
printinfo "Please authorize device access"
sudo bash -c "$CURSCRIPT $ARGS"
else
printinfo "Device access granted"
suexecWrap $ARGS
fi
@fazlerabbi37
Copy link

@plugnburn have you considered converting the gist into a proper GitHub (or GitLab) repo? Will give us the possibility to have things more organized IMHO. Like having a wiki for each phone with which version works and which doesn't or an issue to track stuff. Most of the comment here is an issue like My phone doesn't work 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment