📜 ⬆️ ⬇️

Introducing OsmocomBB: 0x03 Software



Hello again! It's time to talk about building software for working with OsmocomBB. At this stage, beginning researchers may have difficulty, so I will try to sort it all out. In this part I will talk about the structure of the project, the principles of interaction between the phone and the computer, and also describe in detail the compilation process. I recommend arming with some Linux distribution, because the server part of the project was developed specifically for this family of operating systems. I also advise you to refrain from using virtual machines, as there may be problems with running applications on the phone due to time delays.

Navigation



Basics of the basics


The GSM protocol stack, which regulates the processes of interaction between mobile phones and base stations, can be divided into 3 logical levels:

A detailed description of this topic can be found in Wikipedia . Most of all, we are interested in the distribution of roles between the telephone and the computer:

')
The physical level works on the phone, the other two are implemented on the computer side. As mentioned in the previous article, the phone and computer interact through the phone’s UART interface.

OsmocomBB Review


Let's start with the fact that OsmocomBB is developed based on the Git version control system, and its source codes are available on the official website git.osmocom.org . Most project features, such as RSSI, an interface for receiving / making voice calls and exchanging SMS messages, are available in the main branch of the project (master). However, the most interesting features are available in the form of branches of the repository - branches (branch):


The remaining branches of the repository mainly contain corrections and innovations of other developers of the project, which sometimes fall into the master branch. OsmocomBB has a lot of development vectors, so any interested developer can join the project development.

Build project


Let's determine the location of files and folders. Based on my experience, I recommend creating the / opt / osmocom folder - in it we will store libraries and cross-compiler. And to build a project, use, for example, a home folder, or another place for which you do not need administrator rights. As a result of the project compilation, you will receive applications (firmware) running on the phone, and programs for interacting with them from the computer (server) side. The build process is described using the example of Ubuntu 14.04, so the command syntax may differ slightly on other distributions. So what do we need?


To compile the source code, we need autoconf, automake, libtool, pkg-config, make and GCC. At the same time create the / opt / osmocom directory:

#      ,     sudo. $ sudo su #  . $ apt get update $ apt-get install libtool shtool automake autoconf git-core pkg-config make gcc #      -. $ mkdir /opt/osmocom 

In the process of assembling source codes, errors often occur. More often than not, there are not enough libraries. On baseband-devel.722152.n3.nabble.com you can find ways to solve most of them - use the search. If the error occurs during the configuration process (autoreconf or ./configure commands), try to resolve it and reconfigure it.

Let's start with libosmocore:

 $ cd /opt/osmocom $ git clone git://git.osmocom.org/libosmocore.git $ cd libosmocore $ autoreconf -i #  pcsclite    libosmocore. $ apt-get install libpcsclite-dev $ ./configure $ make $ make install 

Go ahead. Building a cross-compiler is the main source of errors and takes most of the time. In most cases, the error "@itemx must follow @item" occurs. The fact is that the assembly requires an older version of TexInfo. You can run downgrade manually, or you can use my fixed version of the installer:

 $ cd /opt/osmocom #  -. $ apt-get install build-essential libgmp3-dev libmpfr-dev libx11-6 libx11-dev flex bison libncurses5 libncurses5-dbg libncurses5-dev libncursesw5 libncursesw5-dbg libncursesw5-dev zlibc zlib1g-dev libmpfr4 libmpc-dev texinfo #   . $ git clone https://github.com/axilirator/gnu-arm-installer.git gnu-arm-toolchain $ cd gnu-arm-toolchain #   . $ ./download.sh #    $ ./build.sh 

UPD: Despite the fact that the project site has an updated version of the cross-compiler based on GCC 4.8.2, Binutils 2.21.1 and Newlib 1.19, I recommend using its previous version available in my repository. As a result of the compilation of the code of such forks of the project as DrWhax / osmocom-bb-raw and offlinehacker / osmocombb , the layer1 firmware hangs when trying to synchronize with the base station. In the firmware of the official project repository compiled with the new version of the cross-compiler, similar problems are not observed.

If errors occur, Google will always come to the rescue. Additional libraries may be required. It all depends on your distribution. In any case, you need to achieve a successful build and the message “Build complete!”, After which you need to add the path to the cross-compiler executable files to the PATH environment variable.

 #     . $ su <  > $ cd ~ # ,   /opt/osmocom/gnu-arm-toolchain/install/bin/    #   -, ,    ls. #   : $ gedit .bashrc #      : # export PATH=$PATH:/opt/osmocom/gnu-arm-toolchain/install/bin/ #   . $ source .bashrc #    : $ arm-elf-gcc -v #        . #         bin      PATH. 

Congratulations! Now your system is ready to build OsmocomBB. It's time to build the master branch.

 #      osmocombb: $ mkdir ~/osmocombb $ cd ~/osmocombb #  : $ git clone git://git.osmocom.org/osmocom-bb.git master # : $ cd master/src $ make 

If the error "no such instruction: `eor %edx,%ecx,%ecx,ror'" occurs, then your cross-compiler executable files are not available - check everything again. Remember this sequence of actions - it is used every time you build a new branch. To clone a specific repository branch, use the -b flag, for example:

 #    sylvain/burst_ind: $ cd ~/osmocombb $ git clone git://git.osmocom.org/osmocom-bb.git -b sylvain/burst_ind burst_ind 

Run Hello, world!


The most awaited moment. First you need to clarify the platform of your phone (on the wiki / Hardware / Phones page), for example, for the C123, C115 and C118 - this is Compal E88. The firmware for each platform is located in the same directory under the path src / target / firmware / board /. So, turn off the phone, connect the cable to the computer, then:

 #    : $ cd ~/osmocombb/master/src/ #  ,      E88: $ host/osmocon/osmocon -m c123xor -p /dev/ttyUSB0 target/firmware/board/compal_e88/hello_world.compalram.bin #      . #   ,      . 



Conclusion:
Received PROMPT1 from phone responding with CMD
read_file (target / firmware / board / compal_e88 / hello_world.compalram.bin): file_size = 25180, hdr_len = 4, dnload_len = 25187
got 1 bytes from modem, data looks like: 1b.
got 1 bytes from modem, data looks like: f6.
got 1 bytes from modem, data looks like: 02.
got 1 bytes from modem, data looks like: 00.
got 1 bytes from modem, data looks like: 41 A
got 1 bytes from modem, data looks like: 02.
got 1 bytes from modem, data looks like: 43 C
Received PROMPT2 from phone, starting download
handle_write (): 4096 bytes (4096/25187)
handle_write (): 4096 bytes (8192/25187)
handle_write (): 4096 bytes (12288/25187)
handle_write (): 4096 bytes (16384/25187)
handle_write (): 4096 bytes (20480/25187)
handle_write (): 4096 bytes (24576/25187)
handle_write (): 611 bytes (25187/25187)
handle_write (): finished
got 1 bytes from modem, data looks like: 1b.
got 1 bytes from modem, data looks like: f6.
got 1 bytes from modem, data looks like: 02.
got 1 bytes from modem, data looks like: 00.
got 1 bytes from modem, data looks like: 41 A
got 1 bytes from modem, data looks like: 03.
got 1 bytes from modem, data looks like: 42 B
Received DOWNLOAD ACK from phone, your code is running now!
battery_compal_e88_init: starting up

OsmocomBB Hello World (revision osmocon_v0.0.0-1754-gfc20a37-modified)
================================================= ====================
Device ID code: 0xb4fb
Device Version code: 0x0000
ARM ID code: 0xfff3
cDSP ID code: 0x0128
Die ID code: 14190d16f00215c6
================================================= ====================
REG_DPLL = 0x2413
CNTL_ARM_CLK = 0xf0a1
CNTL_CLK = 0xff91
CNTL_RST = 0xfff3
CNTL_ARM_DIV = 0xfff9
================================================= ====================
REG_DPLL = 0x2413
CNTL_ARM_CLK = 0xf0a1
CNTL_CLK = 0xff91
CNTL_RST = 0xfff3
CNTL_ARM_DIV = 0xfff9
================================================= ====================
entering interrupt loop
BAT-ADC: 549 4 0 0 1023 392 449 127
Charger at 34 mV.
Battery at 3753 mV.
Charging at 0 mA.
Battery capacity is 69%.
Battery range is 3199..3999 mV.
Battery full at 468 LSB ... full at 585 LSB
Charging at 239 LSB (204 mA).
BCICTL2 = 0x3ff
battery-info.flags = 0x00000000
bat_compal_e88_chg_state = 0

If something goes wrong while loading, the bootloader may hang. Just remove the battery for a couple of seconds and reinsert it.

What happens and how does it work?


We will deal with everything in order. When launched, the osmocon program blocks the serial port and waits for the bootloader messages, sending special beacon messages. The built-in phone loader when you press the power button sends to the serial port a request to download the firmware (ACK). If nobody answers him, he simply sends the message "@ftmtoolerror". In our case, osmocon accepts the request (as indicated by the line “Received PROMPT1 from phone responding with CMD”) and responds with a special message (file_size = 25180, hdr_len = 4, dnload_len = 25187). Then the phone loader either agrees to load the firmware (Received PROMPT2 from the phone, starting download), or reports an error. As soon as the firmware is loaded (handle_write (): finished) into RAM, the loader notifies us again (Received DOWNLOAD ACK from phone, your code is running now!) And provides power to the board (battery_compal_e88_init: starting up). Your phone shows the well-known words “Hello, world!”, And the code already running on it is written to the console. Cool!

FTMTOOL error


This error in most cases occurs due to cable and / or converter problems, when osmocon cannot communicate with the bootloader. Make sure that the GND, RxD and TxD pins are properly connected, and the chipset name of your USB-TTL converter is included in the list of recommended ones . Try pressing the power button again after a few seconds. Also, for some phone models and converters, the value of the -m key of the osmocon program should be specified without ending xor, for example, -m c123 instead of -m c123xor .

Osmocon output in case of error:
got 1 bytes from modem, data looks like: 00.
got 1 bytes from modem, data looks like: 00.
got 1 bytes from modem, data looks like: 81.
got 4 bytes from modem, data looks like: 1b f6 02 00 ...
got 1 bytes from modem, data looks like: 41 A
got 1 bytes from modem, data looks like: 01.
got 1 bytes from modem, data looks like: 40 @
Received PROMPT1 from phone responding with CMD
read_file (chainloader): file_size = 32, hdr_len = 4, dnload_len = 39
got 1 bytes from modem, data looks like: 66 f
got 1 bytes from modem, data looks like: 74 t
got 1 bytes from modem, data looks like: 6d m
got 1 bytes from modem, data looks like: 74 t
got 1 bytes from modem, data looks like: 6f o
got 1 bytes from modem, data looks like: 6f o
got 1 bytes from modem, data looks like: 6c l
Received FTMTOOL from phone, ramloader has aborted
got 1 bytes from modem, data looks like: 65 e
got 1 bytes from modem, data looks like: 72 r
got 1 bytes from modem, data looks like: 72 r
got 1 bytes from modem, data looks like: 6f o
got 1 bytes from modem, data looks like: 72 r
got 1 bytes from modem, data looks like: 00.

Does it violate the law?


The application launched by us does not interact with the cellular network, but before launching other applications, I would like to dwell on the issue of legality. In some countries, using third-party software to interact with cellular networks is illegal. The conditions on which cellular services are provided may vary among different operators, and, more often than not, do not allow the use of non-certified software. Therefore, by default, the ability to transfer data to the network is disabled. If you know what you are doing and your actions do not violate existing laws, you can enable data transfer before building the project in the src / target / firmware / Makefile file by uncommenting the line "CFLAGS + = -DCONFIG_TX_ENABLE". The project authors have devoted a small wiki / LegalAspects page to this issue.

The structure of the project, the process of downloading applications (firmware)


There are three folders in the root folder: doc, include, and src. There is hardly anything useful in doc or include. We are most interested in the src folder, which contains the following directories:


More information about the structure of the project can be found in the file README.development. The source codes of the OsmocomBB applications are stored in the src / target / firmware / apps folder, and their compiled versions are available separately for each platform in the / src / target / firmware / board folder. You can find two versions of the compiled application (firmware): compalram and highram. The first option is to download using the standard phone loader. Some “voluminous” applications, for example, RSSI, cannot be loaded with the standard loader, therefore, “chain loading” is performed: first, the custom loader loader.compalram.bin is loaded, which loads firmware of the highram type. The syntax of the "download chain":

 #       : $ host/osmocon/osmocon -m c123xor -p /dev/ttyUSB0 -c target/firmware/board/compal_e88/rssi.highram.bin target/firmware/board/compal_e88/chainload.compalram.bin #      chainload   osmocon,     . #    -c: $ host/osmocon/osmocon -m c123xor -p /dev/ttyUSB0 -c target/firmware/board/compal_e88/rssi.highram.bin 

As soon as you need to shut down the application, stop the osmocon process, and then press and hold the shutdown button for two seconds.

What is interesting here?


A few words about the applications available in the various branches of the project. A more detailed review will be devoted to the following article, but for now you can read the official wiki / Applications documentation.

Interaction with equipment



Applications 2 and 3 levels of the GSM protocol stack



Applications running on the phone



The end?


This article has come to an end. I hope this material will be useful as a novice researcher of mobile networks, and a specialist in this field. In the next article I will talk more about applications compiled by us and their practical application, but for now, by tradition, leave a list of interesting articles, presentations and speeches:


Successes to all!

Navigation


Source: https://habr.com/ru/post/260213/


All Articles