Skip to content

Instantly share code, notes, and snippets.

@plugnburn
Last active March 26, 2024 13:21
  • Star 61 You must be signed in to star a gist
  • Fork 21 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
@funkypou
Copy link

funkypou commented Mar 20, 2017

Hi,
Thank you for this tool. It works on the new Nokia 150 (first Nokia feature phone from HMD Global after the Microsoft era), at least for the commands I tried (sim off, phonebook-read phone). It can be useful for a nice csv backup of the contacts. The "sim off" command is also my only way to activate the flight mode on the Nokia 150 as it seems impossible throw the menus. It's just too bad I have to carry a linux computer all the time to activate it. :-)

@rolfen
Copy link

rolfen commented Apr 20, 2019

Watch out for the following on Nokia 105:

nokiatool.sh expert audioroute speaker
nokiatool.sh expert loopback on

It created a feedback loop so strong that my phone was vibrating like crazy.
I stopped it quickly.

nokiatool.sh expert loopback off

My speaker still seems to be functional after enduring a few seconds of that, but surely it can't be very good.

@lilkwa
Copy link

lilkwa commented Aug 11, 2019

I try this script with my Nokia 105 2019 (TA-1174), but I can not perform any commands. It turns out that my PC does not recognize my phone, below is the result of lsusb, the blank space is my phone. Do you guys have any suggestions ?

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 13d3:3490 IMC Networks
Bus 001 Device 003: ID 04f2:b52b Chicony Electronics Co., Ltd
Bus 001 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 005: ID 2e04:0010
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

@plugnburn
Copy link
Author

I try this script with my Nokia 105 2019 (TA-1174), but I can not perform any commands. It turns out that my PC does not recognize my phone, below is the result of lsusb, the blank space is my phone. Do you guys have any suggestions ?

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 13d3:3490 IMC Networks
Bus 001 Device 003: ID 04f2:b52b Chicony Electronics Co., Ltd
Bus 001 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 005: ID 2e04:0010
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Never perform this on 105-2019 and 110-2019. They are based on Spreadtrum SC6531EFM, not MediaTek.

@Nokiauser
Copy link

I get an error. " /nokiatool.sh: line 35: read: terminal attribute assignment error: system call aborted." What to do?

Copy link

ghost commented Jan 15, 2020

I have Nokia 130 DS (uSD card supported). I connect to Ubuntu 18.04. Phone gives option of Charging only or Mass storage. I tried both. None of the case I see Serial device on dmesg log. But I can see device detected as "Charging only" or "Mass storage device" properly in both the cases. Does it need any specific driver in linux too to access modem?
Charging only mode log:
[ 2710.492683] usb 1-7: new full-speed USB device number 13 using xhci_hcd
[ 2710.642739] usb 1-7: New USB device found, idVendor=0421, idProduct=069a
[ 2710.642744] usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2710.642748] usb 1-7: Product: Nokia 130 (RM-1035)
[ 2710.642751] usb 1-7: Manufacturer: Nokia

Mass storage mode log:
[ 2738.537053] usb 1-7: new full-speed USB device number 14 using xhci_hcd
[ 2738.687584] usb 1-7: New USB device found, idVendor=0421, idProduct=06fb
[ 2738.687589] usb 1-7: New USB device strings: Mfr=2, Product=3, SerialNumber=4
[ 2738.687592] usb 1-7: Product: Nokia 130 (RM-1035)
[ 2738.687595] usb 1-7: Manufacturer: Nokia
[ 2738.687598] usb 1-7: SerialNumber: 538696701709530
[ 2738.689303] usb-storage 1-7:1.0: USB Mass Storage device detected
[ 2738.690849] scsi host7: usb-storage 1-7:1.0
[ 2739.717952] scsi 7:0:0:0: Direct-Access MEDIATEK FLASH DISK PQ: 0 ANSI: 0 CCS
[ 2739.718603] sd 7:0:0:0: Attached scsi generic sg6 type 0
[ 2739.719223] sd 7:0:0:0: [sdg] 30318592 512-byte logical blocks: (15.5 GB/14.5 GiB)
[ 2739.719610] sd 7:0:0:0: [sdg] Write Protect is off
[ 2739.719617] sd 7:0:0:0: [sdg] Mode Sense: 03 00 00 00
[ 2739.720004] sd 7:0:0:0: [sdg] No Caching mode page found
[ 2739.720016] sd 7:0:0:0: [sdg] Assuming drive cache: write through
[ 2739.729903] sdg: sdg1
[ 2739.733021] sd 7:0:0:0: [sdg] Attached SCSI removable disk

Copy link

ghost commented Jan 15, 2020

I have Nokia 130 DS (uSD card supported). I connect to Ubuntu 18.04. Phone gives option of Charging only or Mass storage. I tried both. None of the case I see Serial device on dmesg log. But I can see device detected as "Charging only" or "Mass storage device" properly in both the cases. Does it need any specific driver in linux too to access modem?
[ 2710.492683] usb 1-7: new full-speed USB device number 13 using xhci_hcd
[ 2710.642739] usb 1-7: New USB device found, idVendor=0421, idProduct=069a
[ 2710.642744] usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 2710.642748] usb 1-7: Product: Nokia 130 (RM-1035)
[ 2710.642751] usb 1-7: Manufacturer: Nokia

Hi @plugnburn, thanks for this awesome tool. Now it works. Modem device nodes were not created earlier due to FTDI modem driver does not support this Vendor ID + Device ID pair. I just did a work around with tip from internet, got the node created and script works fine! Good job.
Loading device driver with hack:
Remove phone from computer
# modprobe ftdi_sio
# echo 0421 069a > /sys/bus/usb-serial/drivers/ftdi_sio/new_id
Now plugin the phone to device

dmesg log after loading device driver:
[ 5341.209602] usbcore: registered new interface driver ftdi_sio
[ 5341.209615] usbserial: USB Serial support registered for FTDI USB Serial Device

dmesg log after plugin the device:
[ 5462.131516] usb 1-7: new full-speed USB device number 16 using xhci_hcd
[ 5462.281669] usb 1-7: New USB device found, idVendor=0421, idProduct=069a
[ 5462.281674] usb 1-7: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 5462.281678] usb 1-7: Product: Nokia 130 (RM-1035)
[ 5462.281681] usb 1-7: Manufacturer: Nokia
[ 5462.282838] ftdi_sio 1-7:1.0: FTDI USB Serial Device converter detected
[ 5462.282931] usb 1-7: Detected FT2232C
[ 5467.427607] ftdi_sio ttyUSB1: Unable to read latency timer: -110
[ 5467.427759] ftdi_sio ttyUSB1: Unable to write latency timer: -32
[ 5467.427935] usb 1-7: FTDI USB Serial Device converter now attached to ttyUSB1
[ 5467.428271] ftdi_sio 1-7:1.1: FTDI USB Serial Device converter detected
[ 5467.428400] usb 1-7: Detected FT2232C
[ 5472.547675] ftdi_sio ttyUSB2: Unable to read latency timer: -110
[ 5472.547833] ftdi_sio ttyUSB2: Unable to write latency timer: -32
[ 5472.548007] usb 1-7: FTDI USB Serial Device converter now attached to ttyUSB2

Terminal screen to send sms successfully
_# ./nokiatool.sh sms +91XXXXXYYYYY hi buddy
Device access granted
Connecting to device...

Sending SMS...
./nokiatool.sh: line 35: read: error setting terminal attributes: Interrupted system call
SMS sent_

@albertomario
Copy link

Hello,
Any idea how i could get this working on windows, using for example mingw?
In device manager i get Nokia 150 (RM-1190).

@ibravos75
Copy link

Hello

Thanks for this tool, it's my only hope to get my contacts from an old Microsoft RM-1133. Please help me understand some things before i setup a Linux box:

  • Do i need a special cable to connect to the phone or just a USB cable from pc to phone?
  • Do i need to find and install this Nokia usb2serial driver mentioned in the script or it comes with Linux? I wasn't able to find it on the net.

Thank you very much

@Barracuda72
Copy link

* Do i need a special cable to connect to the phone or just a USB cable from pc to phone?

No, you could use any standard USB cable, as soon as it's 4-wire (e.g. not only for charging)

* Do i need to find and install this Nokia usb2serial driver mentioned in the script or it comes with Linux? I wasn't able to find it on the net.

You don't need anything except kernel FTDI driver (already there if you are using standard kernel from your distribution).

@goldcon88
Copy link

Is there any way to use this to disable the radio and games functions?

@luc-ass
Copy link

luc-ass commented Nov 8, 2021

Hey there! Thank you for this fantastic tool! Has anyone found a way to reliably go back to the home screen after a inputting a command using the key emulation method?

Why? I am reprogramming call redirections using USSD-Commands via Keypad Emulation, but this only works if I am on the same reliable starting point.

EDIT: We have moved on from Keypad Emulation to AT+CCFC, which is the right command for call diversion. The response message is missing, but the command is still working fine. AMA if you run into this problem.

EDIT2: After lots of testing we discovered, that nokiatool.sh somehow removes " from arguments. This resulted in AT+CCFC commands not working (needs to have this format: AT+CCFC=0,3,"+1234567890",145 - Reference Chapter 9.5). So now we added the following to nokiatool.sh, which works fine:

# Redirect Calls: nokiatool redirectCalls number
# number in international format
# pauses 10s if successful, to let the network answer

function redirectCalls {
    local number="$1"
    printinfo "Changing call redirection..."
    sendATcmd "AT+CCFC=4,3,\"$number\",145"
    local resp=$(readResponse '+CCFC')
	if [[ $? -eq 0 ]]; then
		printinfo "Changed redirection"
		sleep 10
	else
		printinfo "Redirection failed, please try again"
	fi
}

@blueray453
Copy link

blueray453 commented Nov 8, 2021

Does not import all the contacts from the csv file. I have 248 contacts.

When I import using nokiatool.sh phonebook-import phone < nokia106.csv it says 248 contacts imported into ME memory.

However, when I checked the memory, it has only has ~200 contacts.

So, it is not importing all the contacts though it is saying that it has imported all the contacts.

@dreirund
Copy link

dreirund commented Feb 5, 2022

I made an Arch Linux AUR package of it (in reality, it is just a recipe which still fetches the source from this gist, so I do not distribute other people's content): → Here.

Question: What is the license of this package? For now I have stated

No license text came with this software. Assume all copyright to the authors, (c) Suborg 2016, https://gist.github.com/plugnburn/5b2582be521944f739e1.

according to the header of the script presented here.

For packaging, I have made a patch which applies small modifications:

--- nokiatool.sh.org	2022-02-05 17:07:46.889322592 +0100
+++ nokiatool.sh.new	2022-02-05 17:35:20.669270861 +0100
@@ -6,2 +6,4 @@
-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)
+if [ -z "${MODEM}" ]; then # The serial port to be used can be controlled by the command line; if not set, use a default:
+  read -e -i '/dev/ttyUSB1' -p 'Specify device to interact with (e.g. /dev/ttyUSB1): ' MODEM  # Nokia opens two serial ports, we usually need the second one to send control commands
+fi
+# For not auto-recognised devices something like a manual `modprobe usbserial vendor=0x0421 product=0x069a` might be needed beforehand.
@@ -505 +507 @@
-	$DRIVERINIT
+	# "${DRIVERINIT[@]}" # Here some initialisation commands could be placed.
@@ -527 +529 @@
-	sudo bash -c "$CURSCRIPT $ARGS"
+	bash -c "$CURSCRIPT $ARGS"

Maybe there is something interesting for you in there, too.

Regards!

@dreirund
Copy link

dreirund commented Mar 13, 2022

The line DRIVERINIT='modprobe usbserial vendor=0x0421 product=0x069a' is no longer needed; for exactly that phone (Nokia 130) automatic driver loading has been implemented in the kernel: See → here.

This just had to be reported upstream to the Linux kernel USB mailing list.

So, if anyone does encounter a phone which needs manual driver binding/ loading, please report it to linux-usb [at] vger (dot) kernel )dot) org together with an output of lsusb -vv for that device.

Regards!

@ibravos75
Copy link

Hello. Thanks again for this tool, it was the only thing that worked. MOBILedit didn't even manage to connect to my Nokia 105.

To give some hope to windows users, i report that i ran it successfully on a windows laptop. Using a bootable Ubuntu USB stick of course :-)

It was impossible to read all the phonebook at once. I was getting just about 50 entries so i had to read, delete the entries i read and repeat the process.

Thanks for all the hard work of reverse engineering undocumented features.

@ptrcnull
Copy link

works on Nokia 216 (RM-1187, 0421:0002), thanks!

@Olu-Ieazy
Copy link

Please how do I get started? and can it work on my Nokia 105 (2019) TA-1174

@plugnburn
Copy link
Author

plugnburn commented Aug 12, 2023

@dreirund Hello, thanks a lot for the AUR package, really hadn't thought back then the tool would go so far. Added public domain notice to the script.

Also, I'm in the process of creating a more modern version of this tool (in POSIX AWK) adapted to modern MT6261D-based feature phone models which are a bit more limited in the set of commands they expose. I'll announce it here but I've left GitHub long ago.

You can also see another experiment of mine, a JS-based tool (needs Chromium-based browsers) at TekBuster.

@plugnburn
Copy link
Author

Please how do I get started? and can it work on my Nokia 105 (2019) TA-1174

For 105-2019, as well as more recent versions of 105, there is no way to do the same. It's based on a different chipset family, Unisoc (ex-Spreadtrum) SC6531E, and runs a different OS (Mocor) on a different kernel (ThreadX).

@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