2011年12月14日 星期三

[Router] DMZ

iptables -t nat -A PREROUTING -i ppp0 -p all -j DNAT --to-destination 192.168.0.100

[Router] NAT

# Flush NAT table rules
  iptables -F -t nat
  iptables -X -t nat
  iptables -Z -t nat
  iptables -t nat -P PREROUTING  ACCEPT
  iptables -t nat -P POSTROUTING ACCEPT
  iptables -t nat -P OUTPUT      ACCEPT

# Accept eth0 for all resources
iptables -A INPUT -i eth0 -j ACCEPT

# Enable router function
echo "1" > /proc/sys/net/ipv4/ip_forward

# Enable NAT function
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o ppp0 -j MASQUERADE

[3G] D-Link DWM-156

A clear way to make DWM-156 possible.

1. add usbfs or put it in the /etc/fstab
mount -t usbfs none /proc/bus/usb

fstab:
none    /proc/bus/usb   usbfs   defaults        0       0

2. modem switch
usb_modeswitch -v 0x07d1 -p 0xa804 -m 0x01 -M 5553424312345678000000000000061b000000020000000000000000000000

3. insmod usbserial.ko
insmod /lib/modules/2.6.30/kernel/drivers/usb/serial/usbserial.ko vendor=0x07d1 product=0x7e11

In this stage, /dev/ttyUSB0, /dev/ttyUSB1 and /dev/ttyUSB2 should be appearing.

4. Unlock PIN or not. (xxxx is the PIN code.)
echo -e "AT+CPIN=xxxx\r" > /dev/ttyUSB2

5. /etc/ppp/peers/3g

noauth
nodetach
debug
lock
crtscts
/dev/ttyUSB3
115200
noipdefault
mtu 1500
mru 1500
usepeerdns
local
noccp
refuse-chap
lcp-echo-interval 20
lcp-echo-failure 3
defaultroute
novj
nobsdcomp
nopcomp
noaccomp
nodeflate
linkname 3g
connect "/bin/chat -v -f /etc/ppp/3g_chat"
disconnect '/bin/chat -v -t15 ABORT "BUSY" ABORT "ERROR" ABORT "DIALTONE" "" "\K" "" "ATH" '

6. /etc/ppp/3g_chat

ABORT 'BUSY'
ABORT 'NO CARRIER'
ABORT 'ERROR'
TIMEOUT 10
'' AT
OK AT+CGDCONT=1,"IP","internet",""
OK ATDT*99#
CONNECT ""

7. pppd call 3g
Then ppp0 should appear.

PS: The ISP is "Chunghwa".

[USB] hotplug

    ACTION ... "add", "remove"
    PRODUCT ... USB vendor, product, and version codes (hex)
    TYPE ... device class codes (decimal)
    INTERFACE ... interface 0 class codes (decimal)

    USB_DEVICE (vendorId, productId)
        ... matching devices with specified vendor and product ids
    USB_DEVICE_VER (vendorId, productId, lo, hi)
        ... like USB_DEVICE with lo <= productversion <= hi
    USB_INTERFACE_INFO (class, subclass, protocol)
        ... matching specified interface class info
    USB_DEVICE_INFO (class, subclass, protocol)
        ... matching specified device class info

[3G] ppp-2.4.5

environment variable:
[ipv6]
LLLOCAL
LLREMOTE

BUNDLE
PEERNAME
ORIG_UID
PPPLOGNAME
PPPD_PID
IPLOCAL
IPREMOTE
DNS1
DNS2
USEPEERDNS
OLDIPLOCAL
OLDIPREMOTE
MACREMOTE
UID
DEVICE
SPEED
IFNAME
LINKNAME
CONNECT_TIME
BYTES_SENT
BYTES_RCVD

ip-pre-up:

* Pppd will now run /etc/ppp/ip-pre-up, if it exists, after creating
  the ppp interface and configuring its IP addresses but before
  bringing it up.  This can be used, for example, for adding firewall
  rules for the interface.

2011年12月13日 星期二

[3G] AT commands

"AT+COPS?": Which ISP.
"AT+CGMM": Model name
"AT+CPIN=xxxx": Unlock PIN.


手機 AT 指令集
http://www.360doc.com/content/06/0727/10/10450_165786.shtml
Sierra 320U
Sierra 320U with Telstra
AT commands
手機 AT 指令集
List of AT commands

[iOS] Location

LocateMe:
http://developer.apple.com/library/ios/#samplecode/LocateMe/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007801
This demonstrates the two primary use cases for the Core Location Framework: getting the user's location and tracking changes to the user's location.

GeocoderDemo:
http://developer.apple.com/library/ios/#samplecode/GeocoderDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011097
This sample application demonstrates using a CLGeocoder instance to perform forward and reverse geocoding on strings and dictionaries. The application also includes an example distance calculator that will display the distance between two placemarks.


Teslameter:
http://developer.apple.com/library/ios/#samplecode/Teslameter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008931

This application implements a Teslameter, a magnetic field detector. It displays the raw x, y, and z magnetometer values, a plotted history of those values, and a computed magnitude (size or strength) of the magnetic field.
The use of the Core Location API for getting "heading" data is contained in the TeslameterViewController class. It creates a CLLocationManager object and uses it to get heading by invoking -[CLLocationManager startUpdatingHeading]. It implements the CLLocationManagerDelegate APIs for receiving heading and updates its user interface accordingly.

Breadcrumb:
http://developer.apple.com/library/ios/#samplecode/Breadcrumb/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010048
Demonstrates how to draw a path using the Map Kit overlay, MKOverlayView, that follows and tracks the user's current location. The included CrumbPath and CrumbPathView overlay and overlay view classes can be used for any path of points that are expected to change over time. It also demonstrates what is needed to track the user's location as a background process.


Regions:
http://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010726

This sample demonstrates proper use of region monitoring, significant location changes, and handling location events in the background on iOS. The sample uses an MKMapView that allows the user to add and remove regions to monitor, as well as a UITableView to display the region enter/exit/fail events that occur. When the application goes into the background, location updates are stopped and significant location changes are started. Likewise, when the application enters the foreground, location updates are started again and significant location changes are stopped. When location updates occur in the background, a badge is added to the homescreen icon displaying the number of region enter/exit/fail events logged.


Current Address
http://developer.apple.com/library/ios/#samplecode/CurrentAddress/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009469

Demonstrates basic use of MapKit, displaying a map view and setting its region to current location.
It makes use of the MKReverseGeocoder class that provides services for converting your map coordinate (specified as a latitude/longitude pair) into information about that coordinate, such as the country, city, or street. A reverse geocoder object is a single-shot object that works with a network-based map service to look up placemark information for its specified coordinate value. To use placemark information is leverages the MKPlacemark class to store this information.


MapCallouts:
http://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009746
Demonstrates the use of the MapKit framework, displaying a map view with custom MKAnnotations each with custom callouts. An annotation object on a map is any object that conforms to the MKAnnotation protocol and is displayed on the screen as a MKAnnotationView. Through the use of the MKAnnotation protocol and MKAnnotationView, this application shows how you can extend annotations with custom strings and left/right calloutAccessoryViews.

2011年11月30日 星期三

[E-Mail] Introduce oneself

Dear Mr. Green,

I learned from the newspaper that your company wants to hire an English interpreter. I'm very interested in this job and I would like the opportunity to be interviewed.
To begin, I would like to introduce myself to you. My name is WaHaHa Liu, and I'm twenty-five years old. I graduated from Foreign Languages Department of National Taiwan University in 2008. I have three years' English teaching experience in a middle school. I am good at English, especially spoken English. In addition, I can speak a little Japanese and can talk with foreigners in Japanese. Generally speaking, I believe I am qualified for this job posting.
Enclosed herewith are a copy of my diploma and my resume for your reference.
Your prompt reply would be greatly appreciated.

Sincerely yours,
WaHaHa Liu

2011年11月27日 星期日

[E-Mail] Seeking a Job

Dear Sir,

I'm very excited and delighted over the good news that you are recruiting an administrative assistant. From the enclosed resume, you can see that I once worked in a famous multinational corporation for three years. I am very skilled at dealing with routine office work, and my major in college was office automation systems. So it should be clear that I am qualified for the job.
With respect to salary, my requirement is four thousand dollars one month. I assure you that if appointed, I will do my best to meet or exceed your expectations.
I hope I may be granted an interview, so I can fully explain my qualifications.
Looking forward to hearing from you soon.

Sincerely yours,
Lulala Yea

2011年11月25日 星期五

[E-Mail] Hotel Reservations

Dear Sir or Madam,

Please reserve a single room with a shower and air conditioning from Jan 1st to Jan 5th, under the name of Jack Hsu.
I'd like you to provide a room on the seventh floor, overlooking the whole city, if possible. I am arriving on the afternoon of Jan 1st and leaving on the morning of the Jan 5th.
An early confirmation for this reservation would be much appreciated.

Sincerely yours,
Jack Hsu

2011年11月24日 星期四

[E-Mail] Train Ticket Reservations

Dear Sir or Madam,

I'd like to book a hard seat for the T123 train from A to B on January 21st.
I hope the tickets for T123 haven't been all booked up on that day, but if the tickets have been sold out, please inform me as soon as possible.

I appreciate your early confirmation.
Sincerely yours,
Jack

[E-Mail] Airline Ticket Reservations

Dear Sir or Madam,

I am going to fly from A to B on the earliest flight. Could I book one economy class seat on a flight leaving A on May 12th?
The Agricultural Bank of China has been instructed to pay the fare and booking fee, and I would ask you to submit your invoice directly to them?

I will appreciate your early confirmation.
Sincerely yours,
Brain

2011年11月15日 星期二

[Unix Programming] Zombie

Zombie: Child process terminates without parent's waiting.
As a result, all you have to do is to wait the child process while terminating.


void waitchild() {
  signal( SIGCHLD, waitchild); // re-enable the signal to fit all systems
  while( wait(NULL) <= 0 )
    /*NOTHING*/;
}


int
main (int argc, char **argv)
{
  signal( SIGCHLD, waitchild);
  if (fork() == 0) {
    // child process
  } else {
    // parent
  }
}

Refer:
http://home.educities.edu.tw/shirock/comp/Anti_zombie_process.htm
http://starryalley.twbbs.org/blog/index.php?/archives/683-linux-zombie-process.html

2011年11月13日 星期日

[Google MAP] Address to Google Map

Address -> longitude and latitude -> KML -> Google Map

Address to longitude and latitude:
http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html

KML:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>

<name>Vincent Cheng</name>
<description><![CDATA[test]]></description>
<Style id="style">
<IconStyle>
<Icon>
<href>http://maps.gstatic.com/mapfiles/ms2/micons/blue-dot.png</href>
</Icon>
</IconStyle>
</Style>

<Placemark>
<name>Test1</name>
<description><![CDATA[]]></description>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>120.913872,24.639008,0.000000</coordinates>
</Point>
</Placemark>

<Placemark>
<name>Test2</name>
<description><![CDATA[]]></description>
<styleUrl>#style</styleUrl>
<Point>
<coordinates>120.916405,24.642361,0.000000</coordinates>
</Point>
</Placemark>

</Document>
</kml>

2011年11月8日 星期二

[C] call by value/reference/address

Call by Value, Call by Address(Pointer), C++ includes Call by Reference
http://csie-tw.blogspot.com/2010/03/call-by-valuecall-by-pointercall-by.html

Call by Value:
int main()
{
  int x=1;
  printf("x=%d\n", x);
  foo(x);
  printf("x=%d\n", x);
}
void foo(int x)
{
  x++;
}

result:
1
1


Call by Address/Pointer:
int main()
{
  int x=1;
  printf("x=%d\n", x);
  foo(&x);
  printf("x=%d\n", x);
}
void foo(int *x)
{
  (*x)++;
}

result:
1
2


Call by Reference:(C++)
int main()
{
  int x=1;
  printf("x=%d\n", x);
  foo(x);
  printf("x=%d\n", x);
}
void foo(int &x)
{
  x++;
}

result:
1
2

[C] pointer to function

#include <stdio.h>
#include <stdlib.h>

void func(int);

main(){
      void (*fp)(int);

      fp = func;

      (*fp)(1);
      fp(2);

      exit(EXIT_SUCCESS);
}

void
func(int arg){
      printf("%d\n", arg);
}

2011年10月11日 星期二

[Protocol] L2TP

L2TP tunnel protocol
http://en.wikipedia.org/wiki/Layer_2_Tunneling_Protocol

MTU tuning for L2TP
http://www.cisco.com/en/US/tech/tk801/tk703/technologies_tech_note09186a0080094c4f.shtml

IP header
http://www.freesoft.org/CIE/Course/Section3/7.htm

TCP header
http://www.freesoft.org/CIE/Course/Section4/8.htm

UDP header
http://www.networksorcery.com/enp/protocol/udp.htm


L2TP header
http://www.networksorcery.com/enp/protocol/l2tp.htm

L2TP images
http://images.yourdictionary.com/l2-tp

MTU/MSS sizes
http://www.cherrot.com/2011/09/pptp-l2tp-over-pppoe-mtu-mru.html

Ethernet MinSize = 512bit = 64 Byte
Ethernet MaxSize = 1518 Byte
so Ethernet IP MTU = 1518 - 18 ( 6 SRCMAC+ 6 DSTMAC+ 2 TYPE+ 4 CRC) = 1500 B
so Ethernet IP TCP MSS = 1500 - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1460 B
so Ethernet IP UDP MTU/MRU = 1500 - 28 ( 20 IP_HEADER + 8 UDP_HEADER ) = 1472 B
so PPPoE MTU/MRU = 1500 - 8 ( 6 PPPoE_SESSION + 2 PPP_HEADER ) = 1492 B
so TCP over PPPoE MSS = 1492 ( PPPoE MTU/MRU ) - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1452
so PPTP MTU/MRU = 1500 - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1444 B
so TCP over PPTP MSS = 1444 ( PPTP MTU/MRU ) - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1404
so L2TP MTU/MRU = 1500 - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1460 B
so TCP over L2TP MSS = 1460 ( L2TP MTU/MRU ) - 40 ( 20 IP_HEADER + 20 TCP_HEADER) = 1420 B
so PPTP over PPPoE MTU/MRU = 1492 ( PPPoE MTU/MRU ) - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1436 B
so PPTP over PPTP MTU/MRU = 1444 ( PPTP MTU/MRU ) - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1388 B
so PPTP over L2TP MTU/MRU = 1460 ( L2TP MTU/MRU ) - 56 ( 20 IP_HEADER + 20 TCP_HEADER + 12 GRE_HEADER + 4 PPP_HEADER ) = 1404 B
so L2TP over PPPoE MTU/MRU = 1492 ( PPPoE MTU/MRU ) - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1452 B
so L2TP over PPTP MTU/MRU = 1444 ( PPTP MTU/MRU ) - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1404 B
so L2TP over L2TP MTU/MRU = 1460 ( L2TP MTU/MRU ) - 40 ( 20 IP_HEADER +8 UDP_HEADER + 8 L2TP_HEADER + 4 PPP_HEADER ) = 1420 B
Adjusting IP MTU, TCP MSS, and PMTUD
http://www.cisco.com/en/US/tech/tk870/tk877/tk880/technologies_tech_note09186a008011a218.shtml
MTU
http://en.wikipedia.org/wiki/Maximum_transmission_unit
MSS
http://www.tcpipguide.com/free/t_TCPMaximumSegmentSizeMSSandRelationshiptoIPDatagra-3.htm

2011年9月12日 星期一

[English] Hang, Pull, Take

hang up a sign
hang up the telephone
hand on the phone
hang from the ceiling
hang out the sheets

pull weeds off
pull out of the station
pulled up to the curb
pull done the shade
pull into the station
curtains have been pulled shut
pulling over a car to the curb

take his seat
take off his shoes
take down the signs
take notes
take an order
take something out of the box
take part in

[English] Get, Put, Set

get out of the vehicle
get off the bus
get on (into) a train
get across the street

put on his shirt
put up a sign
put away some boxes
put out the fire

set up a microphone
set down his bag
set out some items
set aside the chairs

2011年8月30日 星期二

Intel WiDi

Intel WiDi: 利用無線技術將 NB 的螢幕投射到顯示的裝置上,如電視、投影機、電腦螢幕等。NB 除了無線連結 WiDi 顯示器,亦可”同時”連線其它的無線網路上網。
要使用 Intel WiDi,需要特定的 Intel WiFi 網卡與 WiDi 裝置。

http://www.iqmore.idv.tw/intel-widi-intel-wireless-display-experience
http://scl13.com/intel-wireless-display-widi/
http://www.techbang.com.tw/posts/6109-asus-u41sv-intel-widi-create-home-video-center-with-wireless

2011年8月10日 星期三

[Linux] Read disk capacity

vincent@vincent-Ubuntu:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             449G   49G  377G  12% /

1. df -h | awk '{if ($1 == "/dev/sda1") {print $2}}'
449G

2. df -h | grep sda1 | awk '{print $2}'
449G

2011年8月3日 星期三

[Linux] Samba Settings

1. Samba variables
2. Password Configuration options
3. Set Samba password by smbpasswd.
    echo -ne "123456\n123456\n" | smbpasswd -c /var/samba/smb.conf -as samba

2011年7月13日 星期三

[Android] MIPS on Android - Application

1. Getting Started with Android

2. Android on MIPS Source Code

3. Build MIPS platform
$ export TARGET_PRODUCT=generic
$ export TARGET_ARCH=mips
$ export TARGET_ARCH_VARIANT=mips32-fp
$ source build/envsetup.sh
$ make -j4

2011年7月1日 星期五

[Linux] callback function

Callback function
The program did "call" the function is initiative, but "callback" function is passive. For example, interrupt handler or event handler was called in some specific situations, they were "callback" functions.
The implementation for callback function is typically a function point in C.

The use of function point is like an abstraction layer. Every driver has to implement the same functions, just like r8169.c ethernet driver must implement the functions related to the pci_driver struct needed.


static struct pci_driver rtl8169_pci_driver = {
        .name           = MODULENAME,
        .id_table       = rtl8169_pci_tbl,
        .probe          = rtl8169_init_one,
        .remove         = __devexit_p(rtl8169_remove_one),
#ifdef CONFIG_PM
        .suspend        = rtl8169_suspend,
        .resume         = rtl8169_resume,
        .shutdown       = rtl_shutdown,
#endif
};

2011年6月28日 星期二

[Linux] script to exclude CVS directory

# find sbin/ -not -name "Entries" -not -name "Root" -not -name "Repository" -not -name "CVS" -not -name "." -exec install -m 755 {} $(INSTALL_DIR)/sbin \;

To delete svn files with "!":


# svn st | grep ! | sed 's/!/svn --force del/g' > run.sh
edit run.sh and add "#!/bin/sh" in first line.
# ./run.sh

2011年6月27日 星期一

[Linux] Device/File system test script

#!/bin/ash

i=1
while true; do
        FILENAME=/mnt/hd/test.tmp
        BLOCKSIZE=1M
        BLOCKCOUNT=100

        echo "--- Write ($i) ---"
        dd if=/dev/zero of=$FILENAME bs=$BLOCKSIZE count=$BLOCKCOUNT conv=sync

        echo 3 > /proc/sys/vm/drop_caches
        echo 0 > /proc/sys/vm/drop_caches

        echo "--- Read ($i) ---"
        dd if=$FILENAME of=/dev/zero bs=$BLOCKSIZE count=$BLOCKCOUNT

        rm -f $FILENAME
        i=$(($i+1))
done

2011年5月12日 星期四

USB OTG

USB OTG: USB On-The-Go
讓 USB 同時具有 Master/Slave 的功能。

例如:
外接式硬碟具備USB OTG,接上數位相機後,外接式硬碟變成Master,可經由單鍵複製數位相機內的相片,數位相機的記憶卡就可以空出來繼續照新的相片。回家後,外接式硬碟接上電腦,又變成Slave,可透過電腦存取硬碟裡的相片。好處便在於,數位相機和外接式硬碟之間不需要第三方加入控制,便稱之為On-The-Go。

2011年4月27日 星期三

Add 32-bit library to 64-bit server

Ubuntu 10 - 64bit
apt-get update
apt-get install ia32-libs
apt-get install lib32z1

Fedora10 - 64bit
1. for /lib
yum install compat-libstdc++-33
yum install libstdc++.i386

2. error
/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory
yum install glibc-devel.i386

CentOS - 64bit

yum install libstdc++.i686
yum install compat-libstdc++-33.i686
yum install glibc-devel.i686
yum install libzip.i686

2011年4月14日 星期四

SVN related

find . -name ".svn" -delete


# checkout
svn co svn+ssh://user@your.server.net/path/to/repo

2011年4月12日 星期二

Moving SVN repository to another server

Refer: http://www.petefreitag.com/item/665.cfm

Step 1: Backup your old Repository

svnadmin dump /path/to/repository > repo_name.svn_dump

Step 2: Create the new Repository

svnadmin create /path/to/repository

Step 3: Import your old repository into the new one

svnadmin load /path/to/repository < repo_name.svn_dump