2010年11月25日 星期四

Management Data Input/Output

轉錄於Nano雞排's Blog

Management Data Input/Output簡稱MDIO,MDIO提供MAC(Media Access Control)如何去存取PHY的標準,制定於802.3裡面。

這張圖我想表達MAC/PHY之間的關係,MAC屬於data link層,PHY屬於Physcial層。


MDIO有兩組訊號線,MDC(Management Data Clock),由圖就可以理解是由STA(Station Management)提供的,而且和TX_CLK/RX_CLK無關。MDIO是一個bidirectional signal,用於PHY和STA之間傳送控制訊號。


frame format

PRE (preamble)STA的每一個指令都會先送出連續32bit的1和PHY取得同步。
ST (start of frame)算是一個pattern,告知PHY這個後面就是MDIO frame了。
OP (operation code)10為read,01為write。
PHYAD (PHY Address)這個MDIO bus上面每個PHY都要有獨一無二的address,讓STA辨識,5個bit,所以最多可有32個PHY在這一組MDIO bus上面。
REGAD (Register Address)5個bit,允許每個PHY可以有32組register。
TA (turnaround)當PHY執行wtite時,TA就是單純的送出10,而當PHY是要read時,STA和PHY會在第一個bit會輸出高阻抗(high-impedance),PHY接著會在第二個bit送出0,後面PHY就會吐出data給STA了,看下面的時序圖就會清楚了


圖檔來源:http://www.tech-regal.com/post/Ethernet-MII.html


參考資料:
  1. IEEE 802.3, http://standards.ieee.org/getieee802/download/802.3-2008_section2.pdf
  2. http://www.tech-regal.com/post/Ethernet-MII.html
  3. http://en.wikipedia.org/wiki/Management_Data_Input/Output

2010年11月16日 星期二

Colasoft packet builder

Colasoft packet builder是十分實用的軟體,透過它可以讓你快速的測試網路協定,基本上,你可以把它看做是packet generator,你只需要把wireshark的capture log餵給它,你就可以任意修改在log中的封包並傳送
打開軟體後先import一個packet cap檔


隨便選擇一個封包然後在下方的editor中編輯欄位如ip,mac…


在封包上點選右鍵選擇傳送,就可以把封包丟到受測平台


這套軟體可以節省protocol驗證的時間,不用特別去寫packet generator,更重要的是,它是free tool.

From http://daydreamer.idv.tw/rewrite.php/read-61.html

2010年11月11日 星期四

iptables with l7-filter

簡介
Linux netfilter的外掛模組,可讓iptables對應用層過濾分析,像是p2p,im,..等
(http://l7-filter.sourceforge.net/)

安裝l7-filter需要以下檔案
Linux kernel source(http://www.kernel.org)
iptables source(http://netfilter.org)
netfilter-layer7(http://sourceforge.net/project/showfiles.php?group_id=80085)
l7-protocols definitions(http://sourceforge.net/project/showfiles.php?group_id=80085)

ps:Kernel compatibility
http://l7-filter.sourceforge.net/kernelcompat

..................................................................................................
安裝步驟

1
先下載所需要的檔案

2
kernel部份
ps:需已安裝過kernel source,並讓/usr/src/linux可指向核心
2.1修正核心patch
用netfilter-layer7-vX.Y/kernel-2.6.*-layer7-X.Y.patch修正核心patch
ps:patch版本必須與目前核心相同,可看netfilter-layer7-vX.Y/readme
2.2重新編譯核心,並增加Layer 7 match support
2.3開始編譯核心
2.4確認開機檔是用新的核心,並reboot

3
iptables部份
3.1修正iptables的patch
用netfilter-layer7-vX.Y/iptables-layer7-X.Y.patch修正iptables source,並安裝修正過的iptables
3.2將iptables指令,指向修正過的iptables
3.3安裝l7-protocols definitions
預設會裝在/etc/l7-protocols/

.......

安裝過程大致如下
1
下載以下檔案後解壓縮到/usr/local/src
netfilter-layer7-v2.0
iptables-1.4.0
l7-protocols-2005-12-16

2.1
cd /usr/src/linux
patch -p1 < /usr/local/src/netfilter-layer7-v2.0/kernel-2.6.13-2.6.14-layer7-2.0.patch
2.2
make mrproper
make oldconfig
會出現 Layer 7 match support (EXPERIMENTAL)... [N/m/?] (NEW) -> 可選m或按enter
make menuconfig
確定是否為 Layer 7 match support
2.3
make clean
make bzImage
make modules
make modules_install
make install
2.4
reboot

3.1
cd /usr/local/src/iptables-1.4.0
patch -p1 < ../netfilter-layer7-v2.0/iptables-layer7-2.0.patch
chmod +x ./extensions/.layer7-test
make clean
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
3.2
cd /sbin
mv iptables iptables.old
ln -s /usr/local/sbin/iptables iptables
3.3
cd /usr/local/src/l7-protocols-2005-12-16
make install

.......................................................................................
用法
-m layer7 --l7proto < protocol> -j < target>
簡介
Linux netfilter的外掛模組,可讓iptables對應用層過濾分析,像是p2p,im,..等
(http://l7-filter.sourceforge.net/)

安裝l7-filter需要以下檔案
Linux kernel source(http://www.kernel.org)
iptables source(http://netfilter.org)
netfilter-layer7(http://sourceforge.net/project/showfiles.php?group_id=80085)
l7-protocols definitions(http://sourceforge.net/project/showfiles.php?group_id=80085)

ps:Kernel compatibility
http://l7-filter.sourceforge.net/kernelcompat

..................................................................................................
安裝步驟

1
先下載所需要的檔案

2
kernel部份
ps:需已安裝過kernel source,並讓/usr/src/linux可指向核心
2.1修正核心patch
用netfilter-layer7-vX.Y/kernel-2.6.*-layer7-X.Y.patch修正核心patch
ps:patch版本必須與目前核心相同,可看netfilter-layer7-vX.Y/readme
2.2重新編譯核心,並增加Layer 7 match support
2.3開始編譯核心
2.4確認開機檔是用新的核心,並reboot

3
iptables部份
3.1修正iptables的patch
用netfilter-layer7-vX.Y/iptables-layer7-X.Y.patch修正iptables source,並安裝修正過的iptables
3.2將iptables指令,指向修正過的iptables
3.3安裝l7-protocols definitions
預設會裝在/etc/l7-protocols/

.......

安裝過程大致如下
1
下載以下檔案後解壓縮到/usr/local/src
netfilter-layer7-v2.0
iptables-1.4.0
l7-protocols-2005-12-16

2.1
cd /usr/src/linux
patch -p1 < /usr/local/src/netfilter-layer7-v2.0/kernel-2.6.13-2.6.14-layer7-2.0.patch
2.2
make mrproper
make oldconfig
會出現 Layer 7 match support (EXPERIMENTAL)... [N/m/?] (NEW) -> 可選m或按enter
make menuconfig
確定是否為 Layer 7 match support
2.3
make clean
make bzImage
make modules
make modules_install
make install
2.4
reboot

3.1
cd /usr/local/src/iptables-1.4.0
patch -p1 < ../netfilter-layer7-v2.0/iptables-layer7-2.0.patch
chmod +x ./extensions/.layer7-test
make clean
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
3.2
cd /sbin
mv iptables iptables.old
ln -s /usr/local/sbin/iptables iptables
3.3
cd /usr/local/src/l7-protocols-2005-12-16
make install

.......................................................................................
用法
-m layer7 --l7proto < protocol> -j < target>
可過濾的protocol可參考http://l7-filter.sourceforge.net/protocols
常見p2p protocol如下
gnutella 可阻擋foxy
bittorrent 可阻擋bittorrent 通訊協定
fasttrack 可阻擋kazaa
edonkey 可阻擋eDonkey,eMule
xunlei 可阻擋迅雷
ex:
在prerouting封鎖即時通
iptables -t mangle -A PREROUTING -m layer7 --l7proto yahoo -j DROP
不讓edonkey能進入本機
iptables -I INPUT -m layer7 --l7proto edonkey -j DROP
封鎖foxy
iptables -t mangle -A PREROUTING -m layer7 --l7proto gnutella -j DROP
iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnutella -j DROP




其他參考
http://l7-filter.sourceforge.net/L7-HOWTO-Netfilter



可過濾的protocol可參考http://l7-filter.sourceforge.net/protocols
常見p2p protocol如下
gnutella 可阻擋foxy
bittorrent 可阻擋bittorrent 通訊協定
fasttrack 可阻擋kazaa
edonkey 可阻擋eDonkey,eMule
xunlei 可阻擋迅雷
ex:
在prerouting封鎖即時通
iptables -t mangle -A PREROUTING -m layer7 --l7proto yahoo -j DROP
不讓edonkey能進入本機
iptables -I INPUT -m layer7 --l7proto edonkey -j DROP
封鎖foxy
iptables -t mangle -A PREROUTING -m layer7 --l7proto gnutella -j DROP
iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnutella -j DROP




其他參考
http://l7-filter.sourceforge.net/L7-HOWTO-Netfilter







from http://systw.net/note/af/sblog/more.php?id=124

2010年11月10日 星期三

Read ext3/ext4 Partition from Windows

Ext2Read is an explorer like utility to explore ext2/ext3/ext4 files. It now supports LVM2 and EXT4 extents. It can be used to view and copy files and folders. It can recursively copy entire folders. It can also be used to view and copy disk and file


2010年10月28日 星期四

利用 ICMP 模擬 G.729 語音封包來測試 VoIP 品質

G.729 語音壓縮的標準,是採用週期性的方式每 20 ms 產生一個 20 bytes 的語音封包 (Voice Payload),之後當語音封包封裝成IP 格式,其實在裡面已經增加了 3 個 header,分別是 RTP (12 bytes), UDP (8 bytes), IP (20 bytes),共 60 bytes 所以在設定參數如下:

-s size 參數設定為 52 (ICMP 自己會加上 8bytes 在 header , 所以最後大小為 60 bytes)
-i interval 設定為 0.02 (G.729 預設為 20 ms)
-c count 設定為 100 , 即送 100 個封包,此處可視情況增減

需先切換為 root
su -
再下 ping 指令
ping -s 52 -i 0.02 -c 100 Destination IP

如果 ping 的統計結果有出現 packet loss 的情況,可能即為該線路頻寬不足 (小於1M/64k)、不良(雜訊)或者是內部流量過大等情形,即使用者打 VoIP 會有通話斷斷續續的情況。


2010年10月26日 星期二

在Uboot下使用ckermit透過com port來download image file

u-boot的官方網站已經說很清楚了。看這裡:
http://www.denx.de/wiki/view/DULG/UBootCmdGroupDownload#Section_5.9.5.3.

minicom is another popular serial communication program. Unfortunately, many users have reported problems using it with U-Boot and Linux, especially when trying to use it for serial image download. It's use is therefore discouraged.



* 下載 cku211.tar.gz 

* 解壓縮後 編譯: make linux;make install



* 編譯完成後執行 : kermit 


* Kermit的配置範例(可設定於~/.kermrc):
set line /dev/ttyS0
set speed 115200
set carrier-watch off
set handshake none
set flow-control none
robust
set file type bin
set file name lit
set rec pack 1000
set send pack 1000
set window 5


* 連上板子 : connect or c


*  切換 : 按下Ctrl + \  , 再按C 可以跳回kermit; 若欲跳回console可以再輸入c or connect。

* uboot上輸入 :  eraseall b

*  傳送檔案 send /path/filename



 補充:搭配minicom使用

*使用minicom -s,到"檔案傳輸協定"或"File Transfer protocols"裡的G和H,

     G設定為/usr/local/bin/kermit -i -l %f -b %b -s           Y U Y N N,

     H設定為/usr/local/bin/kermit -i -l %f -b %b -r           N D Y N N。

* 開始傳檔
執行Ctrl+A -> S,接著選完檔案後即可開始傳送檔案了

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...