2015年8月21日星期五

ESP8266 - A Great Product

In ESP8266 SDK,
Something that interests me:
1) Support RTC.
2) SDK provides several functions to get the time using SNTP protocol.
3) Support SSL (Only allow single client connection only)
The default value of maximum SSL packet size is 2KB.
The maximum size packet can be adjusted.

It is good enough for a single IOT SOC chip (Just HKD 12)...

Then, focus on the SSL, found one more interesting thing...
Someone lists out the object symbols in his blog:)
http://41j.com/blog/2015/01/esp8266-sdk-library-symbols/

Many standardized cryptography algorithms (RSA, SHA1, MD5, AES..) have already provided in the object library files,
but they are not explicitly exposed by the vendor.

In other words, once we disassemble the code,
and trace how the parameters passed in these functions (XTENSA ABI).
Actually, it is not necessary to re-implement the cryptography function (greatly reduce the code size).

ESP8266 Initial Test

The module I use:  ESP-8266 ESP-01

1) Wire Connection
Since the USB to UART TTL module may not provide sufficient power for ESP-01,
use external power supply is recommended.

3.3V <-> ESP8266 VCC
3.3V <-> ESP8266 CH_PD
USB to UART TTL module RX <-> ESP8266 TX
USB to UART TTL module TX <-> ESP8266 RX
GND <-> USB to UART TTL module GND <-> ESP8266 GND

*: GPIO0 should be connected to GND if we want to update the firmware. Reboot is required before update.
For general purpose, GPIO0 can be float.

==========================================

2) Testing

In Linux environment, CuteCOM is recommended for testing the communication.

Below is the setup procedures:

Device: /dev/ttyUSB0
Baud rate: 115200
Data bits: 8
Stop bits: 1
Parity: None
Handshake: uncheck both
linefeed: default should be set to CR LF (sometimes you need to switch to use HEX Input format e.g. send raw byte)

Open the COM port and listen the response.
reboot the ESP-01 module.
It should return [Ready] string.

P.S.:
Please update to the latest firmware before use:
The latest firmware uses 115200, 8N1, AT COMMAND LINE END - CR LF for communication.
Before update the firmware, we need to download the SDK and the FLASH PROGRAMMING TOOLS first.

More details can be found in SDK documentation.



In CuteCOM, enter the following commands.
Input AT
response OK means success.

Input AT+CWMODE=1
For STATION MODE only . (3=STATION MODE+ SOFTAP MODE)

Input AT+CWLAP
List available access point.

============================================

3) NTP Client Implementation

Get current time stamp using NTP

#RESET
AT+RST

#GET FIRMWARE VER
#AT+GMR

#SET TO STATION MODE
AT+CWMODE=1

#LIST AP
AT+CWLAP

#CONNECT ACCESS POINT
AT+CWJAP="SSID","Password"

#MAKE CONNECTION.
#參考自:https://github.com/sandeepmistry ... lient/NTPClient.ino
#Other NTP Server might not work...
AT+CIPSTART="UDP","129.6.15.28",123

#SEND NTP PACKET
AT+CIPSEND=48

IN CuteCOM, change to HEX input.
Input the following:
E30006EC0000000000000000314E31340000000000000000000000000000000000000000000000000000000000000000

It should return 48 bytes packet.

2015年4月12日星期日

ECC notes

ECC Brief

Q = kP can be expand as several of point doubling + point addition operation

"point doubling + point addition operation" can be expand as several field multiplication + field addition operation




Selection


Selection at the field level:
F2m, Fp, Fpm
poly basis / normal basis
Field arithmetic algorithm

Selection at the elliptic curve level:
affine coordinate / projective coordinate
point addition / double algorithm

protocol level:
appropriate protocol (key exchange / signature)
algorithm for kP



Fp


affine coordinate
projective coordinate - one is called Jacobin. 


Doubling: 2J -> J 4M, 3S
Mixed Coordinate : J+A -> J 8M + 3S



F2m


Field Addition - very simple and fast - just XOR

Field Multiplication - Shift and Add Method / Comb method -> field reduction / LSD (Least significant. digit serial) Multiplier method



Point Multiplication


Binary method: (m/2)PointAdd + (m) PointDouble
NAF method: (m/3) PointAdd + (m) PointDouble
Montgomery Multiplication: (6M+5S+3A)m + (1I+10M)


Message Protocol


Diffie Hellman Key Exchange (man-in-the-middle attack?):

PrC ·PuS =PrS ·PuC =PrS ·PrC ·G
Use same G (base point) and poly.

Server private key: PrS
Client private key: PrC

Server public key: PuS
Client public key: PuC


ECDSA:





2014年12月2日星期二

Add Board in U-Boot

1) Create Directory: /board/{VENDOR}/{BRDNAME}

2) Check similar driver? GPIO?

2a) For example, if we want to modify GPIO, create the C src file in /driver/gpio/{MARCH}_gpio.c

2b) In the /drivers/gpio/Makefile, add:
COBJS-$(CONFIG_{MARCH}_GPIO) += {BRDNAME}_gpio.o

2c) Create file: include/configs/{BRDNAME}.h
add #define CONFIG_{BRDNAME}_GPIO

3) CPU

3a) Create configs/{BRDNAME}_defconfig in the /configs directory
CONFIG_{ARCH}=y
CONFIG_TARGET_{BRDNAME}=y


3b) In arch/{ARCH}/Kconfig, add:
config TARGET_{BRDNAME}
    bool "Support {BRDNAME}"
    select CPU_{MARCH}


3c) In arch/{ARCH}/Kconfig, add:
source "board/{VENDOR}/{BRDNAME}/Kconfig"

4) Place relevant src files in
/board/{VENDOR}/{BRDNAME}

5) Add your Device in boards.cfg

6) Add Kconfig file:
if TARGET_{BRDNAME}

config SYS_BOARD
    default "{BRDNAME}"

config SYS_VENDOR
    default "{VENDOR}"

config SYS_SOC
    default "{ARCH}"

config SYS_CONFIG_NAME
    default "{BRDNAME}"

endif


2014年11月30日星期日

Communicate thru crossover network cable in Windows

Hints: Some network cards support auto crossover, do not need crossover cable actually.

Computer A:
manual set IP: static, 192.168.2.1
subnet mask: 255.255.255.0
manual set Gateway: 192.168.2.2
preferred DNS Server: 192.168.2.2


Computer B:
manual set IP: static, 192.168.2.2
subnet mask: 255.255.255.0
manual set Gateway: 192.168.2.1
preferred DNS Server: 192.168.2.1



Support exFAT in debian

Install relevant applications:
  sudo apt-get install exfat-fuse exfat-utils

List the disk
  fdisk -l 

Format:

  mkfs.exfat -n LABEL /dev/sdXn
Check file system command:
  fsck.exfat /dev/sdXn

Install flash plugin

apt-get install flashplugin-nonfree

2014年3月31日星期一

My conkyrc file (~/.conkyrc)

background yes
use_xft yes
xftfont Sans:size=8
xftalpha 1
update_interval 1.0
total_run_times 0
own_window yes
own_window_transparent yes
own_window_type desktop
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
minimum_size 100 100
maximum_width 300
draw_shades yes
draw_outline no
draw_borders no
draw_graph_borders yes
default_color white
default_shade_color black
default_outline_color white
alignment top_right
gap_x 12
gap_y 80
no_buffers yes
uppercase no
cpu_avg_samples 2
override_utf8_locale no

TEXT
${color FFFFFF}${font sans-serif:bold:size=8:}SYSTEM${hr 2}
${color FFFFFF}${font sans-serif:normal:size=8}$sysname $kernel $alignr $machine
Host:$alignr$nodename
Uptime:$alignr$uptime

${font sans-serif:bold:size=8}${color FFFFFF}PROCESSORS ${hr 2}${font sans-serif:normal:size=8}${color
FFFFFF}
CPU: ${cpu cpu0}% ${cpubar cpu0}

${font sans-serif:bold:size=8}${color FFFFFF}MEMORY ${hr 2}
${font sans-serif:normal:size=8}${color FFFFFF}RAM $alignc $mem / $memmax $alignr $memperc%
$membar

${font sans-serif:bold:size=8}${color FFFFFF}DISKS ${hr 2}
${font sans-serif:normal:size=8}${color FFFFFF}/ $alignc ${fs_used /} / ${fs_size /} $alignr${fs_used_perc /}%
${fs_bar /}
Home $alignc ${fs_used /home/yip} / ${fs_size /home/yip} $alignr ${fs_used_perc /home/yip}%
${fs_bar /home/yip}

${font sans-serif:bold:size=8}${color FFFFFF}TOP PROCESSES ${hr 2}
${font sans-serif:normal:size=8}${color FFFFFF}
${top_mem name 1}${alignr}${top mem 1} %
${top_mem name 2}${alignr}${top mem 2} %
${top_mem name 3}${alignr}${top mem 3} %
${top_mem name 4}${alignr}${top mem 4} %
${top_mem name 5}${alignr}${top mem 5} %

${font sans-serif:bold:size=8}${color FFFFFF}NETWORK ${hr 2}
${font sans-serif:normal:size=8}${color FFFFFF}IP address: $alignr ${addr enp2s0}

$alignr Download
${downspeedgraph enp2s0}
${downspeed enp2s0}/s $alignr ${totaldown enp2s0}

$alignr Upload
${upspeedgraph enp2s0}
${upspeed enp2s0}/s $alignr ${totalup enp2s0}

${color #FFFFFF}Inbound Connection ${alignr} Local Service/Port$color
 ${tcp_portmon 1 32767 rhost 0} ${alignr} ${tcp_portmon 1 32767 lservice 0}
 ${tcp_portmon 1 32767 rhost 1} ${alignr} ${tcp_portmon 1 32767 lservice 1}
 ${tcp_portmon 1 32767 rhost 2} ${alignr} ${tcp_portmon 1 32767 lservice 2}
 ${tcp_portmon 1 32767 rhost 3} ${alignr} ${tcp_portmon 1 32767 lservice 3}
 ${tcp_portmon 1 32767 rhost 4} ${alignr} ${tcp_portmon 1 32767 lservice 4}
${color #FFFFFF}Outbound Connection ${alignr} Remote Service/Port$color
 ${tcp_portmon 32768 61000 rhost 0} ${alignr} ${tcp_portmon 32768 61000 rservice 0}
 ${tcp_portmon 32768 61000 rhost 1} ${alignr} ${tcp_portmon 32768 61000 rservice 1}
 ${tcp_portmon 32768 61000 rhost 2} ${alignr} ${tcp_portmon 32768 61000 rservice 2}
 ${tcp_portmon 32768 61000 rhost 3} ${alignr} ${tcp_portmon 32768 61000 rservice 3}
 ${tcp_portmon 32768 61000 rhost 4} ${alignr} ${tcp_portmon 32768 61000 rservice 4}
 ${tcp_portmon 32768 61000 rhost 5} ${alignr} ${tcp_portmon 32768 61000 rservice 5}
 ${tcp_portmon 32768 61000 rhost 6} ${alignr} ${tcp_portmon 32768 61000 rservice 6}
 ${tcp_portmon 32768 61000 rhost 7} ${alignr} ${tcp_portmon 32768 61000 rservice 7}
 ${tcp_portmon 32768 61000 rhost 8} ${alignr} ${tcp_portmon 32768 61000 rservice 8}
 ${tcp_portmon 32768 61000 rhost 9} ${alignr} ${tcp_portmon 32768 61000 rservice 9}

install acrobat reader using makepkg

install acrobat reader using makepkg

$wget https://aur.archlinux.org/packages/ac/acroread/acroread.tar.gz
$tar -xvzf acroread.tar.gz
$cd acroread
$makepkg -s
$sudo pacman -U *.pkg.tar.xz

if dependence not found - lib32-gtk2..etc...
enable the multilab section in /etc/pacman.cong
------------------------------------------------------------------------------------------------------

To use the multilib repository, uncomment the [multilib] section in /etc/pacman.conf:
[multilib]
Include = /etc/pacman.d/mirrorlist
You will then need to update the package list by running pacman with the -Sy switch.

Note:
  • If the system has the base-devel package group installed, users must replace the [extra] versions with the [mutlilib] versions as shown below.
  • gcc-multilib is capable of building 32-bit and 64-bit code. You can safely install multilib-devel to replace the packages shown below, but you still need base-devel for the other packages it includes. See https://bbs.archlinux.org/viewtopic.php?id=102828 for more information.
# pacman -S gcc-multilib
resolving dependencies...
warning: dependency cycle detected:
warning: lib32-gcc-libs will be installed before its gcc-libs-multilib dependency
looking for inter-conflicts...
:: gcc-libs-multilib and gcc-libs are in conflict. Remove gcc-libs? [y/N] y
:: binutils-multilib and binutils are in conflict. Remove binutils? [y/N] y
:: gcc-multilib and gcc are in conflict. Remove gcc? [y/N] y
:: libtool-multilib and libtool are in conflict. Remove libtool? [y/N] y

Remove (4): gcc-libs-4.6.1-1  binutils-2.21.1-1  gcc-4.6.1-1  libtool-2.4-4

Total Removed Size:   87.65 MB

Targets (7): lib32-glibc-2.14-4  lib32-gcc-libs-4.6.1-1  gcc-libs-multilib-4.6.1-1  binutils-multilib-2.21.1-1
             gcc-multilib-4.6.1-1  lib32-libtool-2.4-2  libtool-multilib-2.4-2

Total Download Size:    25.04 MB
Total Installed Size:   108.27 MB

Proceed with installation? [Y/n]
Reference: https://wiki.archlinux.org/index.php/makepkg

Important:
Even I do the above operation,
I still miss the lib32-pangox-compat dependency,
I manually build above library (extract, config, make, make install) and then delete the  pangox-compat dependency in the PKGBUILD flag,
and it can normally run now... :(