2015年12月25日 星期五

Using Wireshark to analysis LTE traffic


Development - The Wireshark Wiki
https://wiki.wireshark.org/Development

Chapter 9. Packet dissection
https://www.wireshark.org/docs/wsdg_html_chunked/ChapterDissection.html
9.2. Adding a basic dissector
https://www.wireshark.org/docs/wsdg_html_chunked/ChDissectAdd.html

Creating Your Own Custom Wireshark Dissector - CodeProject
http://www.codeproject.com/Articles/19426/Creating-Your-Own-Custom-Wireshark-Dissector

6.2. Overview
https://www.wireshark.org/docs/wsdg_html_chunked/ChWorksOverview.html


6.4. Capture Files
https://www.wireshark.org/docs/wsdg_html_chunked/ChWorksCaptureFiles.html

HowToDissectAnything - The Wireshark Wiki
https://wiki.wireshark.org/HowToDissectAnything
User DLT (147~162)
od -Ax -tx1 -v /tmp/cnnheaders.txt | text2pcap -l 147 - httpresp.pcap
10.20. User DLTs protocol table
https://www.wireshark.org/docs/wsug_html_chunked/ChUserDLTsSection.html

IttiAnalyzer < OpenAirInterface < Institut Eurecom TWiki
https://twiki.eurecom.fr/twiki/bin/view/OpenAirInterface/IttiAnalyzer
An example of LTE packet dissection can be found oai_l2l3.pcap.
https://twiki.eurecom.fr/twiki/pub/OpenAirInterface/IttiAnalyzer/oai_l2l3.pcap

I was able to dissect oai_l2l3.pcap with Wireshark 1.10, but not 2.0.2.

[Edit] -> [Preferences] -> [Protocols] -> [UDP] -> Eanble [Try heuristic sub-dissectors first]
All the other heuristic settings in mac-lte/rlc-lte/pdcp-lte are removed.

But the UDP heuristic protocols are not enabled by default.
[Analyze] -> [Enabled Protocols] -> Enable:
  • MAC-LTE and mac_lte_udp
  • RLC and rlc_udp
  • RLC_LTE and rlc_lte_udp
  • PDCP-LTE and pdcp_lte-udp


Wireshark: Re: How to use lte_rrc in wireshark?http://seclists.org/wireshark/2010/Feb/476

[Wireshark] Contents of /trunk/epan/dissectors/packet-pdcp-lte.c
http://anonsvn.wireshark.org/viewvc/trunk/epan/dissectors/packet-pdcp-lte.c?revision=31661&view=markup

MAC-LTE - The Wireshark Wiki
https://wiki.wireshark.org/MAC-LTE

RLC-LTE - The Wireshark Wiki
https://wiki.wireshark.org/RLC-LTE

RLC - The Wireshark Wiki
https://wiki.wireshark.org/RLC

LTE RRC - The Wireshark Wiki
https://wiki.wireshark.org/LTE%20RRC

Wireshark解析MAC-LTE - 简书
http://www.jianshu.com/p/4f1991302d63


OpenAirInterface

OAI Objectives
http://www.openairinterface.org/docs/workshop/1_OAI_Workshop_20160122/OAI-obj2016.pdf

OAI License Model | OpenAirInterface
http://www.openairinterface.org/?page_id=101

OAI has
  • OAI soft UE (OpenAirInterface5G)
  • OAI soft eNB (OpenAirInterface5G)
  • OAI soft EPC (OpenairCN)
OpenAirInterface5G: https://gitlab.eurecom.fr/oai/openairinterface5g
OpenairCN: https://gitlab.eurecom.fr/oai/openair-cn

https://www.dropbox.com/home/oai5g_roadmap_seminar/session_1?preview=SYRTEM_ALCATEL_OAI_2nd_Workshop_%233L1-L2API_REV-.pdf
PHY-Openair1
MAC/RLC/PDCP: Openair2

https://gitlab.eurecom.fr/oai/openairinterface5g/blob/master/README.txt
├── openair1 : 3GPP LTE Rel-10 PHY layer + PHY RF simulation and a subset of Rel 12 Features.
├── openair2 :3GPP LTE Rel-10 RLC/MAC/PDCP/RRC/X2AP implementation. 
    ├── LAYER2/RLC/ with the following subdirectories: UM_v9.3.0, TM_v9.3.0, and AM_v9.3.0. 
    ├── LAYER2/PDCP/PDCP_v10.1.0. 
    ├── RRC/LITE
    ├── PHY_INTERFACE
    ├── X2AP
    ├── ENB_APP 
├── openair3: 3GPP LTE Rel10 for S1AP, NAS GTPV1-U for both ENB and UE.
    ├── GTPV1-U
    ├── NAS 
    ├── S1AP
    ├── SCTP
    ├── SECU
    ├── UDP
OpenAirInterface 5G Training
https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/OpenAirDocumentation/Openair5GLab.pptx
openair2
https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/OpenAir2CoreDev
https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/OpenAir2CoreDev/oai_protocol_stack.png



ITTI: InterTask Interface

OpenAirInterface | 5G software alliance for democratising wireless innovation
http://www.openairinterface.org/

Getting Started | OpenAirInterface
http://www.openairinterface.org/?page_id=25

Home | Wiki | oai / openairinterface5G | GitLab
https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home
Openairusage | Wiki | oai / openairinterface5G | GitLab
https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/OpenAirUsage

Towards Open Cellular Ecosystem | OpenAirInterface
http://www.openairinterface.org/?page_id=864

WebHome < OpenAirInterface < Institut Eurecom TWiki
https://twiki.eurecom.fr/twiki/bin/view/OpenAirInterface/WebHome

GetSources < OpenAirInterface < Institut Eurecom TWiki
https://twiki.eurecom.fr/twiki/bin/view/OpenAirInterface/GetSources

AutoBuild < OpenAirInterface < Institut Eurecom TWiki
https://twiki.eurecom.fr/twiki/bin/view/OpenAirInterface/AutoBuild

2nd OAI Workshop | OpenAirInterface
http://www.openairinterface.org/?page_id=1476

Meetingminutes | Wiki | oai / openairinterface5G | GitLab
https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/MeetingMinutes

LTE spec

3GPP Releases
http://www.3gpp.org/specifications/67-releases

3GPP specification Release version matrix
http://www.3gpp.org/DynaReport/SpecReleaseMatrix.htm

Master Telecom Faster - Fast tracks into the LTE Specifications
http://www.mastertelecomfaster.com/index.php

Master LTE Faster - The SpecTool - LTE Protocols
http://www.masterltefaster.com/index.php

LTE/SAE Call Flow Diagrams @ GSM, SIP, H.323, ISUP and IMS Call Flows
http://www.eventhelix.com/realtimemantra/Telecom/#LTE_SAE_Call_Flow_Diagrams

Telecom • Networking • Software
http://www.eventhelix.com/RealtimeMantra/#.VnzvgjWkVC0

LTE (Long Term Evolution) Tutorials and Call Flows
http://www.eventhelix.com/lte/#.VnzxXDWkVC0

Networking Protocol Sequence Diagrams
http://www.eventhelix.com/Realtimemantra/Networking/#.VnzxQDWkVC2



PDCP
http://www.eventhelix.com/lte/presentations/3GPP-LTE-PDCP.pdf

2015年12月11日 星期五

Access SPI bus in u-boot and Linux


Serial Peripheral Interface Bus - Wikipedia, the free encyclopedia
https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus

U-boot SPI test tool

The u-boot command sspi Usage:

sspi - SPI utility command
Usage:
sspi [<bus>:]<cs>[.<mode>] <bit_len> <dout> - Send and receive bits
<bus> - Identifies the SPI bus
<cs> - Identifies the chip select
<mode> - Identifies the SPI mode to use
<bit_len> - Number of bits to send (base 10)
<dout> - Hexadecimal string that gets sent
<dout> is in hex but without the prefix "0x". All others are in decimal.

The following is SPI mode defined in u-boot/include/spi.h. But still depends on the mode that SPI controller/driver can handle:
/* SPI mode flags */
#define SPI_CPHA        0x01                    /* clock phase */
#define SPI_CPOL        0x02                    /* clock polarity */
#define SPI_MODE_0      (0|0)                   /* (original MicroWire) */
#define SPI_MODE_1      (0|SPI_CPHA)
#define SPI_MODE_2      (SPI_CPOL|0)
#define SPI_MODE_3      (SPI_CPOL|SPI_CPHA)
#define SPI_CS_HIGH     0x04                    /* CS active high */
#define SPI_LSB_FIRST   0x08                    /* per-word bits-on-wire */
#define SPI_3WIRE       0x10                    /* SI/SO signals shared */
#define SPI_LOOP        0x20                    /* loopback mode */
#define SPI_SLAVE       0x40                    /* slave mode */
#define SPI_PREAMBLE    0x80                    /* Skip preamble bytes */
It depends on the requirement of the device, as well as the data sent to the device as command. Says we require bus=0, CS=2, data len=32, data=0x51525354, the device require SPI_3WIRE, SPI_CPHA, SPI_CPOL=> mode=0x13 (19).
# sspi 0:2.19 32 51525354
51525354


Linux SPI test tool
Projet spi-tools « Christophe Blaess
http://www.blaess.fr/christophe/2014/08/12/projet-spi-tools/
https://github.com/cpb-/spi-tools
usage: ./spi-config options...
  options:
    -d --device=  use the given spi-dev character device.
    -q --query         print the current configuration.
    -m --mode=[0-3]    use the selected spi mode.
             0: low iddle level, sample on leading edge
             1: low iddle level, sample on trailing edge
             2: high iddle level, sample on leading edge
             3: high iddle level, sample on trailing edge
    -l --lsb={0,1}     LSB first (1) or MSB first (0)
    -b --bits=[7...]   bits per word
    -s --speed=   set the speed in Hz
    -h --help          this screen
    -v --version       display the version number
CPOL=1, idle state is high
CPHA=1, sample on falling
=>mode=3
But there's no 3WIRE related config, and don't know how to decide speed and lsb option.
spi-config -d /dev/spidev0.0 -m 3 -l 0 -b 8
spi-config -d /dev/spidev0.0 -q

2015年12月8日 星期二

Install Android Studio on Ubuntu 14.04.2 LTS

Ubuntu 14.04.2 LTS

sudo apt-get install default-jre

I got this when trying to install Android Studio:

JDK Required: 'tools.jar' seems to be not in Studio classpath.
Please ensure JAVA_HOME points to JDK rather than JRE.
It can be fixed by install JDK(I thought I already did? But I searched all the package installed but there's no tools.jar.) and export the JAVA_HOME.

Java SE Development Kit 7 - Downloads | Oracle Technology Network | Oracle
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html


Installing the JDK Software and Setting JAVA_HOME (Using the GlassFish ESB Installation CLI)
http://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/

Download the JDK from Oracle.
mkdir -p  /usr/java;
cd /usr/java ;
sudo tar xf ~/Downloads/jdk-7u79-linux-x64.tar.gz ;
export JAVA_HOME=/usr/java/jdk1.7.0_79;

Using the Emulator | Android Developers
http://developer.android.com/tools/devices/emulator.html#vm-linux

Download Android Studio and SDK Tools | Android Developers
http://developer.android.com/sdk/index.html

Download Android Studio and unzipped, and enter the directory. Run the following command to start the installation of Android Studio:
cd bin;
./studio.sh

DragonBoard 410c: Module 3 Setting up Your Developing Environment
https://d396qusza40orc.cloudfront.net/phoenixassets/internet-of-things-history/C2M3-ExploringAndroidStudio.pdf



VIM plugin

史丹利部落格: Vim + Trinity + Source Explorer + Tag List + NERD_tree + ctags
闇月千瞳的部落格: 使用 SrcExpl 強化 VIM 的 Source Explorer 能力
http://yuanfarn.blogspot.tw/2013/02/srcexpl-vim-source-explorer.htmlJoe's Notepad: vim + ctags + cscope + taglist + Trinity + NERD_tree + Source Explorer
vim + ctags + cscope + taglist + Trinity + NERD_tree + Source Explorer 

Trinity - the Trinity of taglist, NERDtree and SrcExpl: an IDE works like "Source Insight" : vim online


Vim Taglist plugin
http://vim-taglist.sourceforge.net/

Ctags and Taglist: Convert Vim Editor to Beautiful Source Code Browser for Any Programming Language
http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/
:TlistOpen

minibufexpl.vim - Elegant buffer explorer - takes very little screen space : vim online
http://www.vim.org/scripts/script.php?script_id=159

MiniBufExplorer插件的使用 - - ITeye技术网站
http://suchj.iteye.com/blog/1169566
向前循环切换到每个buffer名上
向后循环切换到每个buffer名上
在打开光标所在的buffer
d 删除光标所在的buffer

2015年12月7日 星期一

VIM script


Vim - map shell command - Stack Overflow
http://stackoverflow.com/questions/9364040/vim-map-shell-command

Note some things:
  1. Don’t use map (without n and nore) unless you have a specific reason. I believe you don’t need this mapping for visual and operator-pending modes (leading n restricts mapping to normal mode only) and you also should not want this mapping to be remappable.
  2. Use to discard count you can occasionally type unless you do know you need it (third version uses two hacks that turn mapping to no-op with a side-effect and does not need ).
  3. Never forget to escape shell arguments.
  4. Version with silent ! (do not forget space after silent, this is why @David Pope’s answer does not work) has at the end. This is because using ! will always provide access to your terminal and thus redraw is needed after command has run.
  5. Versions with system() won’t work if you add an argument containing newline, it is a documented bug. If you don’t want to do so (expand('') won’t ever add newline) it is absolutely safe.
  6. t is a very useful motion. It is better to learn to use it then remap it to something. I suggest ,t as a lhs.
Mapping keys in Vim - Tutorial (Part 1) - Vim Tips Wiki - Wikia
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_1%29

Mapping key sequences
http://osr507doc.sco.com/en/OSUserG/_mapping_key_sequences.html

Vim documentation: help
http://vimdoc.sourceforge.net/htmldoc/help.html
Vim documentation: usr_41
http://vimdoc.sourceforge.net/htmldoc/usr_41.html
Vim documentation: map
http://vimdoc.sourceforge.net/htmldoc/map.html

Learn Vimscript the Hard Way
http://learnvimscriptthehardway.stevelosh.com/

2015年12月4日 星期五

C call graph with cscope

sudo apt-get install xdot
sudo apt-get install cscope

CallGraphviz—依據 cscope、Graphviz 以及 xdot 實作的 call graph visualizer - OpenFoundry
http://www.openfoundry.org/tw/tech-column/8352-callgraphviz-cscopegraphviz-xdot-call-graph-visualizer

git clone https://github.com/chihchun/callgraphviz.git
python visualizer.py
問題
  • 要一個一個symbol自己key進去
  • 無法刪除已key入的symbol
  • 無法Save成.dot檔案

toolchainguru: Bash: C Call Trees and Graphs
http://www.toolchainguru.com/2008/07/bash-c-call-trees-and-graphs.html
The bash script works for me with some modification.
https://github.com/mkl0301/callgraphviz/blob/master/calltree.sh

Functions supported:
  1. downstream X: functions called by X (callee)
  2. upstream X: functions that call X(caller)
  3. subgraph X Y: all code paths that lead from function X to function Y.
  4. related A, B, ... Z: all code paths between an arbitrary set of functions A, B, C, [...] Z
First you need to have your cscope.out generated. Second source the script calltree.sh:
. calltree.sh;
Then:
downstream FUNC1 LEVEL
upstream FUNC1 LEVEL
subgraph FUNC1 FUNC2
related FUNC1...FUNCn

FUNCx: Function name
LEVEL: levels to look into. 0: infinite
The latest script could take the Function name as the first parameter:
Call the built-in function by providing the function name as the first
    parameter:
        ./calltree.sh FUNC PARM1 PARM2...PARM8

Thus I could do the following directly:
./calltree.sh downstream FUNC1 LEVEL


CCTree - C Call-Tree Explorer -- Cscope based source-code browser; code flow analyzer : vim online
http://www.vim.org/scripts/script.php?script_id=2368
Vim CCTree -- Call-tree Explorer plugin
https://sites.google.com/site/vimcctree/
cctree help file
http://sites.google.com/site/vimcctree/cctree.txt
Copy cctree.vim to ~/.vim/plugins/

Load database
    :CCTreeLoadDB
(Please note that it might take a while depending on the  database size)

Save native Xref Db
   :CCTreeSaveXRefDB  cctree.out

Load native XRef Db~
    :CCTreeLoadXRefDB  cctree.out

Get reverse call tree for symbol  <C-\> <
    :CCTreeTraceReverse       
Get forward call tree for symbol
<C-\> >
    :CCTreeTraceForward
Increase depth of tree and update
<C-\> =
    :CCTreeRecurseDepthPlus     
Decrease depth of tree and update
<C-\>  -
    :CCTreeRecurseDepthMinus    



2015年12月3日 星期四

cscope

sudo apt-get install cscope
cat > ~/.vimrc << eof
if has('cscope')
  set cscopetag cscopeverbose

"  if has('quickfix')
"    set cscopequickfix=s-,c-,d-,i-,t-,e-
"  endif

  cnoreabbrev csa cs add
  cnoreabbrev csf cs find
  cnoreabbrev csk cs kill
  cnoreabbrev csr cs reset
  cnoreabbrev css cs show
  cnoreabbrev csh cs help

  command -nargs=0 Cscope cs add \$VIMSRC/src/cscope.out \$VIMSRC/src
endif
eof
cd ~/.vim/plugin/; wget http://cscope.sourceforge.net/cscope_maps.vim

I have the  cscope_maps.vim file(check turtoial [1]), and the .vimrc thing from Vim Tips Wiki [2], but removed the quick fix part, as suggested by the [3]. After removed the quick fix part, all duplicated symbol will ask for selection, even for tags!!!

cscope -Rbk -s XXXX
-R     Recurse subdirectories during search for source files.
-b     Build the cross-reference only.-q     Enable  fast  symbol  lookup  via an inverted index.
-k     ``Kernel Mode'', turns off the use of the  default  include  dir (usually  /usr/include) when building the database, since kernel source trees generally do not use it.
-sdir  Look in dir for additional source files. This option is  ignore if source files are given on the command line.
-q     Enable  fast  symbol  lookup  via an inverted index.

-C     Ignore letter case when searching.
-d     Do not update the cross-reference.
Cscope interactive
^d: Exit cscope.
: Alternate between the menu and the list of matching lines

Contrl-\+
       c: Find functions calling this function (caller)
       d: Find functions called by this function (callee)
       e: Find this egrep pattern
       f: Find this file
       g: Find this definition
       i: Find files #including this file
       s: Find this C symbol
       t: Find this text string




[1] Vim/Cscope tutorial
http://cscope.sourceforge.net/cscope_vim_tutorial.html

Vi with Cscope
http://web.missouri.edu/~hantx/Tools/vi/TonyViNotes/node11.html
  1. Building database for Cscope:
    $ cscope -Rb
    This command makes the Cscope parse all the subdirectories (-R option) and exit without entering awkward Cscope interface.
  2. List all the uses of the symbol under the cursor:
    Ctrl+\s
    That is Control-backslash and then 's'. Select one of items in the list and hit enter, you will jump to the that use. Ctrl+t jump back.
  3. Find functions that under the cursor
    Ctrl+\d
    That is Control-backslash and then 'd'.
  4. Open the file with filename under cursor
    Ctrl+\f
    That is Control-backslash and then 'f'.
  5. Jump back from most recent jumping-off point:
    Ctrl+t
[2] Cscope - Vim Tips Wiki - Wikia
http://vim.wikia.com/wiki/Cscope
A Collection of Vi Tips
http://users.nccs.gov/~fwang2/tools/vinotes.html
Cscope Tutorial
https://courses.cs.washington.edu/courses/cse451/12sp/tutorials/tutorial_cscope.html

[3] Vi + Cscope: using "cscope find c function" in vim, finds multiple results, how to go next - Stack Overflow
http://stackoverflow.com/questions/4399519/vi-cscope-using-cscope-find-c-function-in-vim-finds-multiple-results-how

linux - How to set vim as default cscope editor? - Stack Overflow
http://stackoverflow.com/questions/28121485/how-to-set-vim-as-default-cscope-editor

Using Cscope on large projects (example: the Linux kernel)
http://cscope.sourceforge.net/large_projects.html

2015年12月1日 星期二

BASH: invoked by sh enter POSIX mode

Bash Reference Manual: Bash POSIX Mode
http://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html

 invoked as sh, Bash enters POSIX mode after reading the startup files.

Execute the following script with bash and sh, which also links to sh, get the different result:
~$ cat a
#!/bin/bash
echo a

~$ cat test
#!/bin/bash
source a
echo b

~$ ls /bin/sh -alh
lrwxrwxrwx 1 root root 4 12月  1 16:30 /bin/sh -> bash

~$ bash test
a
b

~$ ./test
a
b

~$ sh test
test: line 2: source: a: file not found