diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/eth0.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/eth0.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/eth0.c	2013-12-25 21:03:05.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/eth0.c	2015-10-20 09:39:25.210212000 +0900
***************
*** 13,28 ****
  #include <sys/fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  
! /* ネットワークにpingして有線LAN(eth0)を検査する */
  int eth0_kensa()
  {
  	unsigned int i;
- 	char buf[256];
  	int flag;
  	char *argv_cmd[10];
  	struct stat st;
! 
  	/* eth0を固定IPで再接続する */
  	for( i = 0 ; ; i++ ) {
  		argv_cmd[0] = "/sbin/ifup";
--- 13,240 ----
  #include <sys/fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include "kensa.h"
  
! int get_id(char *str, int max_index, int *id)
! {
! 	int i, br_index;
! 
! 	for(i=max_index; i>0 && str[i] != ']'; i--);
! 	if(i<=0)
! 	{
! 		printf("Couldn't find ']' while searching for transfer ID\n");
! 		return -1;
! 	}
! 	br_index = i;
! 	str[br_index] = 0;	/* replace ] with NULL */
! 
! 	for(i--; i>=0 && str[i] != '[' && str[i] != ' '; i--);
! 	if(i<=0)
! 	{
! 		printf("Couldn't find '[' while searching for transfer ID\n");
! 		return -1;
! 	}
! 	/* Get ID */
! 	*id = atoi(&str[i+1]);
! 	str[br_index] = ']';	/* restore ] */
! 	return 0;
! 
! }
! 
! int get_transfer_id(char *buf, char *ip, int *id)
! {
! 	char *s;
! 	char str[50];
! 	int sendspeed, rcvspeed, filesize;
! 	int s_speed, r_speed;
! 	double send_bps, rcv_bps;
! 	
! 	sprintf(str, "%s port 5001", ip);
! 	printf("Searching string - \"%s\"\n", str);
! 	s = strstr(buf, str);
! 	if(!s)
! 	{
! 		printf("Not found\n", str);
! 		return -1;
! 	}
! 
! 	return get_id(buf, s-buf, id);
! }
! 
! int get_speed(char *buf, int transfer_id, double *speed_bps, char *str)
! {
! 	char *s;
! 	char *start;
! 	int id;
! 	char *end_s;
! 	start = buf;
! 	while(1)
! 	{
! 		if((s=strstr(start, str)) == 0)
! 			return -1;
! 		/* check ID */
! 		if(get_id(buf, s-buf, &id))
! 			return -1;
! 		if(id != transfer_id)
! 		{
! 			start = s + 5;
! 			printf("Ignoring found ID %d \n", id);
! 			continue;
! 		}
! 		printf("Transfer ID %d found\n", transfer_id);
! 
! 		/* The speed is indicated in the previous value */
! 		for(s--; s>=buf && *s==' '; s--);
! 		if(s < buf)
! 		{
! 			printf("Couldn't find ending SPACE\n");
! 			return -1;
! 		}
! 		end_s = s + 1;
! 		*end_s = 0;		/* replace space by NULL */
! 		for(s--; s>=buf && *s!=' '; s--);
! 		if(s < buf)
! 		{
! 			printf("Couldn't find starting SPACE\n");
! 			return -1;
! 		}
! 		s++;
! 		printf("Got speed %s\n", s);
! 		*speed_bps = atof(s);
! 		*end_s = ' ';	/* restore the space */
! 		return 0;
! 	}
! }
! 
! int get_transfer_speed(char *buf, int transfer_id, int *speed_bps)
! {
! 	double bps;
! 	if(!get_speed(buf, transfer_id, &bps, "Mbits/sec"))
! 	{
! 		/* convert to Kilo bytes */
! 		*speed_bps = bps * 1000;
! 		return 0;
! 	}
! 
! 	if(!get_speed(buf, transfer_id, &bps, "Kbits/sec"))
! 	{
! 		*speed_bps = bps;
! 		return 0;
! 	}
! 	printf("Error: iperf NG - Speed not in Mbits/sec or Kbits/sec. Probably very slow\n");
! 	return -1;
! }
! 
! int iperf_test(char *dev, char *serveraddr, char *clientaddr, int min_send_speed, int min_recv_speed)
! {
! 	int ret = 0;
! 	int fd;
! 	struct stat st;
! 	char *buf;
! 	char cmd[100];
! 	int sendspeed, rcvspeed, filesize;
! 	int send_id, recv_id;
! 	printf("running iperf (%s)...\n", dev);
! 	
! 	sprintf(cmd, "iperf -c %s -d > " IPERF_LOG_FILE, serveraddr);
! 	if(system(cmd))
! 	{
! 		printf("Error: iperf failed\n");
! 		return 1;
! 	}
! 	printf("iperf output: \n");
! 	system("cat " IPERF_LOG_FILE);
! 	printf("\n");
! 	/* get the file length */
! 	stat(IPERF_LOG_FILE, &st);
! 	filesize = st.st_size;
! 	if(filesize == 0)
! 	{
! _err1:
! 		printf("Error: Couldn't determine iperf speed\n");
! 		return 1;
! 	}
! 	fd = open(IPERF_LOG_FILE, O_RDONLY);
! 	if( fd < 0 )
! 	{
! _err2:
! 		printf("Error opening "IPERF_LOG_FILE"\n");
! 		return 1;
! 	}
! 	buf = malloc(filesize);
! 	/* read the file in one go */
! 	if(read(fd, buf, filesize) != filesize)
! 	{
! _err3:
! 		printf("Error reading "IPERF_LOG_FILE"\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	/* get the transfer IDs - search for string "<ip> port 5001" */
! 	if(get_transfer_id(buf, serveraddr, &send_id))
! 	{
! 		printf("Failed to get send ID\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("SEND ID : %d\n", send_id);
! 	if(get_transfer_id(buf, clientaddr, &recv_id))
! 	{
! 		printf("Failed to get receive ID\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("RECEIVE ID : %d\n", recv_id);
! 	printf("Retrieving send speed - ID %d\n", send_id);
! 	if(get_transfer_speed(buf, send_id, &sendspeed))
! 	{
! 		printf("Failed to get send speed\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("Send speed: %d Kbps\n", sendspeed);
! 	printf("Retrieving receive speed - ID %d\n", recv_id);
! 	if(get_transfer_speed(buf, recv_id, &rcvspeed))
! 	{
! 		printf("Failed to get send speed\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	
! 	printf("Receive speed: %d Kbps\n", rcvspeed);
! 
! 	printf("\nSend speed: %d Kbps Receive speed: %d Kbps\n", sendspeed, rcvspeed);
! 	if((sendspeed < 600 || rcvspeed < 600) 
! 			|| ((sendspeed < min_send_speed) || (rcvspeed < min_recv_speed))
! 				&& ((sendspeed+rcvspeed) < (min_send_speed+min_recv_speed)))
! 	{
! 		printf("Error: iperf NG - Very slow\nSend speed=%d Kbps (expected > %d Kbps)\n"
! 					"receive speed=%d Kbps (expected > %d Kbps)\n",
! 							sendspeed, min_send_speed, rcvspeed, min_recv_speed);
! 		ret = 1;
! 	}
! 
! _failed:
! 	free(buf);
! 	close(fd);
! 	return ret;
! }
! 
! /* ネットワークにiperfして有線LAN(eth0)を検査する */
  int eth0_kensa()
  {
  	unsigned int i;
  	int flag;
  	char *argv_cmd[10];
+ 	int ret;
+ 	int count;
  	struct stat st;
! 	char buf[5];
! 	int fd, r;
! _begin:
! 	printf("有線LAN(eth0)を検査します\n");
! 	ret= 0;
! #if 0
  	/* eth0を固定IPで再接続する */
  	for( i = 0 ; ; i++ ) {
  		argv_cmd[0] = "/sbin/ifup";
***************
*** 34,40 ****
  			break;
  		}
  		if( 120 < i ) {
! 			printf("ifconfig eth0 192.168.11.100 up に失敗しました。\n");
  			return(1);
  		}
  		sleep(1);
--- 246,252 ----
  			break;
  		}
  		if( 120 < i ) {
! 			printf("ifup eth0 に失敗しました。\n");
  			return(1);
  		}
  		sleep(1);
***************
*** 56,63 ****
  		printf("ping -I eth0 -c 10 192.168.0.200 に失敗しました。\n");
  		return(1);
  	}
! 	system("ifconfig eth0 down");
! 
  	return 0;
  }
  
--- 268,311 ----
  		printf("ping -I eth0 -c 10 192.168.0.200 に失敗しました。\n");
  		return(1);
  	}
! 	system("ifdown eth0");
  	return 0;
+ #else
+ 	system("ifdown eth0");
+ 	sleep(1);
+ 	system("ifup eth0");
+ 	system("ifconfig eth0 "CLIENT_ETH0_IP_ADDR" up");
+ 	printf("Waiting for eth0...\n");
+ 	count = 0;
+ 	while(count < (ETHLINK_TO*10))
+ 	{
+ 		if(!system("ifconfig eth0 | grep \"UP BROADCAST RUNNING\""))
+ 			break;
+ 		usleep(100000);
+ 		count++;
+ 		if(count%10 == 0)
+ 		{
+ 			printf(".");
+ 			fflush(stdout);
+ 		}
+ 	}
+ 	if(count == (ETHLINK_TO*10))
+ 	{
+ 		printf("eth0 link-up timeout\n");
+ 		goto _done;
+ 	}
+ 	/* routeが確認出きるまで待つ */
+ 	sleep(2);
+ 	ret = iperf_test("eth0", SERVER_ETH0_IP_ADDR, CLIENT_ETH0_IP_ADDR, IPERF_SEND_MIN_SPEED, IPERF_RECV_MIN_SPEED);
+ 	system("ifdown eth0");
+ 	if(ret) {
+ _done:
+ 		if( !kensa_yes_no("\nRetry test? [Y/N] : ")) {
+ 			goto _begin;
+ 		}
+ 		on_error(ret, "有線LAN(eth0)の検査を途中で終了しました！！!\n");
+ 	}
+ 	return ret;
+ #endif
  }
  
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/kensa.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/kensa.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/kensa.c	2015-01-21 13:54:12.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/kensa.c	2015-10-14 10:05:31.016151900 +0900
***************
*** 9,40 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <signal.h>
! #if 0
! #include <string.h>
! #include <sys/fcntl.h>
! #include <sys/ioctl.h>
! #include <sys/time.h>
! #endif
  
  #include "../../../common/samples/common/Shell_execute.c"
  
  int kensa_yes_no(const char *message)
  {
! 	char dummy;
! 
  	printf(message);
  	while(1){
! 		scanf("%c[ynYN]", &dummy);
! 		(void)getchar();	// '\n'の読み捨て
! 		if( toupper(dummy) == 'Y' ) {
! 			break;
! 		} else if( toupper(dummy) == 'N' ) {
  			return 1;
  		}
  	}
- 	return 0;
  }
  
  
  static void sig(int sig)
  {
--- 9,52 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <signal.h>
! #include "kensa.h"
  
  #include "../../../common/samples/common/Shell_execute.c"
  
  int kensa_yes_no(const char *message)
  {
! 	char ch;
  	printf(message);
  	while(1){
! 		scanf(" %c", &ch);
! 		getchar();		/* lose the Enter key */
! 		switch(ch)
! 		{
! 		case 'N':
! 		case 'n':
  			return 1;
+ 		case 'Y':
+ 		case 'y':
+ 			return 0;
+ 		default:
+ 			printf("無効な入力、再試行してください。。。\n");
  		}
  	}
  }
  
+ void close_app(int ret)
+ {
+ 	exit(ret);
+ }
+ 
+ void on_error(int ret, char *msg)
+ {
+ 	if(kensa_yes_no("続行しますか？(Y/N)"))
+ 	{
+ 		printf(msg);
+ 		close_app(ret);
+ 	}
+ }
  
  static void sig(int sig)
  {
***************
*** 62,67 ****
--- 74,87 ----
  	signal(SIGINT, sig);
  	signal(SIGTERM, sig);
  
+ 	system("killall vpif_cam_app");
+ 	system("killall httpd");
+ 	system("killall udhcpc");
+ 	system("killall avahi-daemon");
+ 	system("killall wpa_supplicant");
+ 	system("killall hostapd");
+ 	system("killall iperf");
+ 
  	printf("検査に必要な機器をすべて接続してください。\n");
  	printf("● CKB-1808ボード\n");
  	printf("● CKB-LCD-01ボードとCKB-1808ボードをフラットケーブル2本で接続\n");
***************
*** 109,125 ****
  		fprintf(fd, "auto lo wlan0 eth0\n");
  		fprintf(fd, "iface lo inet loopback\n");
  		fprintf(fd, "iface eth0 inet static\n");
! 		fprintf(fd, "  address 192.168.0.110\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.0.0\n");
! 		fprintf(fd, "  broadcast 192.168.0.255\n");
! 		fprintf(fd, "  gateway 192.168.0.200\n");
  		fprintf(fd, "iface wlan0 inet static\n");
! 		fprintf(fd, "  address 192.168.0.111\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.0.0\n");
! 		fprintf(fd, "  broadcast 192.168.0.255\n");
! 		fprintf(fd, "  gateway 192.168.0.200\n");
  		fclose(fd);
  
  		printf("######################################################\n");
--- 129,145 ----
  		fprintf(fd, "auto lo wlan0 eth0\n");
  		fprintf(fd, "iface lo inet loopback\n");
  		fprintf(fd, "iface eth0 inet static\n");
! 		fprintf(fd, "  address "CLIENT_ETH0_IP_ADDR"\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.2.0\n");
! 		fprintf(fd, "  broadcast 192.168.2.255\n");
! 		fprintf(fd, "  gateway "SERVER_ETH0_IP_ADDR"\n");
  		fprintf(fd, "iface wlan0 inet static\n");
! 		fprintf(fd, "  address "CLIENT_WLAN0_IP_ADDR"\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.3.0\n");
! 		fprintf(fd, "  broadcast 192.168.3.255\n");
! 		fprintf(fd, "  gateway "SERVER_WLAN0_IP_ADDR"\n");
  		fclose(fd);
  
  		printf("######################################################\n");
***************
*** 134,149 ****
  		printf("有線LANコネクタと検査用ルータが接続されている必要があります\n");
  		printf("######################################################\n");
  		if( eth0_kensa() ) {
- 			printf("有線LAN(eth0)の検査を途中で終了しました！！!\n");
- 			exit(1);
  		}
  		printf("######################################################\n");
  		printf("無線LAN(wlan0), SDIOを検査します\n");
  		printf("CM-J100が接続されている必要があります\n");
  		printf("######################################################\n");
  		if( wlan0_kensa() ) {
- 			printf("無線LAN(wlan0), SDIOの検査を途中で終了しました！！!\n");
- 			exit(1);
  		}
  #endif
  		printf("######################################################\n");
--- 154,165 ----
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/kensa.h buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/kensa.h
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/kensa.h	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/kensa.h	2015-10-20 09:16:43.074225500 +0900
***************
*** 0 ****
--- 1,34 ----
+ /*
+  * kensa.h
+  *
+  * CKB Kensa program
+  *
+  * Copyright 2012 Computex Co.,Ltd.
+  *
+  */
+ 
+ #ifndef _KENSA_H_
+ #define _KENSA_H_
+ 
+ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+ 
+ #define SERVER_ETH0_IP_ADDR  "192.168.2.100"
+ #define CLIENT_ETH0_IP_ADDR  "192.168.2.200"
+ 
+ #define SERVER_WLAN0_IP_ADDR	"192.168.3.100"
+ #define CLIENT_WLAN0_IP_ADDR	"192.168.3.200"
+ 
+ #define AP_SSID			"CKBKENSA3"
+ #define AP_PASSWORD		"Computex3"
+ 
+ #define IPERF_LOG_FILE			"/tmp/iperf.log"
+ #define IPERF_TASK_FILE			"/tmp/iperf.task"
+ 
+ #define IPERF_SEND_MIN_SPEED	22000
+ #define IPERF_RECV_MIN_SPEED	28000
+ 
+ #define IPERF_WLAN_SEND_MIN_SPEED	4000
+ #define IPERF_WLAN_RECV_MIN_SPEED	3000
+ 
+ #define ETHLINK_TO				60		/* secs */
+ #endif
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/kensa-server.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/kensa-server.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/kensa-server.c	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/kensa-server.c	2015-10-19 09:59:09.185011900 +0900
***************
*** 0 ****
--- 1,190 ----
+ /*
+  * kensa.c
+  *
+  * CKB-1808 Kensa server program
+  *
+  * Copyright 2013 Computex Co.,Ltd.
+  *
+  */
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <signal.h>
+ #include <sys/fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include "kensa.h"
+ #include <termios.h>
+ 
+ struct termios orig_tio, new_tio;
+ void saveOrigTTYsettings()
+ {
+ 	 tcgetattr(0, &orig_tio);
+ }
+ void restoreOrigTTYsettings()
+ {
+ 	 tcsetattr(0, TCSANOW, &orig_tio);
+ }
+ 
+ _Bool kbhit(u_char *ch)
+ {
+     return read(0,ch,1)?1:0;
+ }
+ 
+ void setKbhitMode()
+ {
+ 	memcpy(&new_tio, &orig_tio, sizeof(struct termios));
+ 	new_tio.c_cc[VMIN]=0;
+     new_tio.c_lflag &= ~ICANON;
+     new_tio.c_lflag &= ~ECHO;
+     new_tio.c_lflag &= ~ISIG;
+ //    new_tio.c_cc[VMIN] = 1;
+     new_tio.c_cc[VTIME] = 0;
+     tcsetattr(0, TCSANOW, &new_tio);
+ }
+ 
+ int kensa_yes_no(const char *message)
+ {
+ 	char ch;
+ 	printf(message);
+ 	while(1){
+ 		scanf(" %c", &ch);
+ 		getchar();		/* lose the Enter key */
+ 		switch(ch)
+ 		{
+ 		case 'N':
+ 		case 'n':
+ 			return 1;
+ 		case 'Y':
+ 		case 'y':
+ 			return 0;
+ 		default:
+ 			printf("無効な入力、再試行してください。。。\n");
+ 		}
+ 	}
+ }
+ 
+ 
+ static void sig(int sig)
+ {
+ 	fflush(stderr);
+ 	printf("signal %d caught\n", sig);
+ 	fflush(stdout);
+ 	exit(1);
+ }
+ 
+ void help()
+ {
+ 	printf("Usage: kensa-server\n");
+ }
+ 
+ /* main() */
+ int main(int argc, char* argv[])
+ {
+ 	int lcd5only = 0;	// 1=LCDボードの検査を行う
+ 	int flag;
+ 	FILE *fd;
+ 	char *argv_cmd[10];
+ 	int rev;			// 0=Rev.A以前、1=Rev.B以降
+ 	struct stat st;
+ 	int filesize;
+ 	char *buf;
+ 	int bufsize = 0;
+ 	u_char ch;
+ #if 0
+ 	/* signal handler */
+ 	signal(SIGSEGV, sig);
+ 	signal(SIGINT, sig);
+ 	signal(SIGTERM, sig);
+ #endif
+ 	system("killall vpif_cam_app");
+ 	system("killall httpd");
+ 	system("killall udhcpc");
+ 	system("killall avahi-daemon");
+ 	system("killall wpa_supplicant");
+ 	system("killall hostapd");
+ 	
+ 	printf("**** Kensa server application\nTerminating any running iperf...");
+ 	system("killall iperf");
+ 	sleep(2);
+ 	/* 検査用のネットワーク設定に変更する */
+ 	system("ifdown eth0");
+ 	system("ifconfig eth0 down");
+ 	system("ifdown wlan0");
+ 
+ 	fd=fopen("/etc/network/interfaces","w");
+ 	fprintf(fd, "auto lo wlan0 eth0\n");
+ 	fprintf(fd, "iface lo inet loopback\n");
+ 	fprintf(fd, "iface eth0 inet static\n");
+ 	fprintf(fd, "  address "SERVER_ETH0_IP_ADDR"\n");
+ 	fprintf(fd, "  netmask 255.255.255.0\n");
+ 	fprintf(fd, "  network 192.168.2.0\n");
+ 	fprintf(fd, "  broadcast 192.168.2.255\n");
+ 	fprintf(fd, "  gateway "SERVER_ETH0_IP_ADDR"\n");
+ 	fprintf(fd, "iface wlan0 inet static\n");
+ 	fprintf(fd, "  address "SERVER_WLAN0_IP_ADDR"\n");
+ 	fprintf(fd, "  netmask 255.255.255.0\n");
+ 	fprintf(fd, "  network 192.168.3.0\n");
+ 	fprintf(fd, "  broadcast 192.168.3.255\n");
+ 	fprintf(fd, "  gateway "SERVER_WLAN0_IP_ADDR"\n");
+ 	fclose(fd);
+ 
+ 	system("ifup eth0");
+ 	system("ifconfig eth0 "SERVER_ETH0_IP_ADDR" up");
+ 	system ("/etc/network/wlan-scripts/HOSTAPD_WPA2.sh n 1 '"AP_SSID"' '"AP_PASSWORD"'");
+ 
+ 	saveOrigTTYsettings();
+ 	setKbhitMode();
+ 	printf("**** Press q to terminate application ****\n");
+ 	while(1)
+ 	{
+ 		if(kbhit(&ch)==1)
+ 		{
+ 			if(ch=='q')
+ 				break;
+ 		}
+ 		system("ps -a | grep \"iperf -s\" | awk '{print $3}' > " IPERF_TASK_FILE);
+ 		system("sync");
+ 		sleep(1);
+ 		/* get the file length */
+ 		stat(IPERF_TASK_FILE, &st);
+ 		filesize = st.st_size;
+ 		if(filesize == 0)
+ 		{
+ 			goto _iperf;
+ 		}
+ 		fd = open(IPERF_TASK_FILE, O_RDONLY);
+ 		if( fd < 0 )
+ 		{
+ 			printf("Error opening "IPERF_TASK_FILE"\n");
+ 			continue;
+ 		}
+ 		if(filesize > bufsize)
+ 		{
+ 			if(bufsize)
+ 				free(buf);
+ 			buf = malloc(filesize);
+ 			bufsize = filesize;
+ 		}
+ 		/* read the file in one go */
+ 		if(read(fd, buf, filesize) != filesize)
+ 		{
+ 			printf("Error reading "IPERF_TASK_FILE"\n");
+ 			close(fd);
+ 			continue;
+ 		}
+ 		close(fd);
+ 		if(!strncmp("iperf", buf, 5))
+ 			continue;
+ _iperf:
+ 		printf("Starting iperf...\n");
+ 		system("iperf -s &");
+ 		printf("iperf started\n");
+ 		sleep(1);
+ 	}
+ 	if(bufsize)
+ 		free(buf);
+ 
+ 	restoreOrigTTYsettings();
+ 	return 0;
+ }
+ 
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/macwrite.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/macwrite.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/macwrite.c	2013-12-25 21:03:40.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/macwrite.c	2015-10-14 10:05:31.020151900 +0900
***************
*** 53,58 ****
--- 53,61 ----
  	printf("有線LANのMACアドレスを設定します。\n");
  	if( buf2[0] == 0x5a ) {
  		printf("現在の設定は %02X:%02X:%02X:%02X:%02X:%02X に設定されています\n", buf2[1], buf2[2], buf2[3], buf2[4], buf2[5], buf2[6]);
+ 		if( 0 != kensa_yes_no("変更しますか？(Y/N)") ) {
+ 			return 0;
+ 		}
  	} else {
  		printf("現在、MACアドレスが設定されていません\n");
  	}
***************
*** 97,102 ****
--- 100,107 ----
  		return(1);
  	}
  #else
+ 	system("ifdown eth0 >& /dev/null");
+ 	system("ifconfig eth0 down >& /dev/null");
  	sprintf(buf, "ifconfig eth0 hw ether 00:A0:0B:%c%c:%c%c:%c%c",c[0],c[1],c[2],c[3],c[4],c[5]);
  	if( system(buf) != 0 ) {
  		printf("有線LAN用EEPROMへのMACアドレス ライトコマンド(ifconfig)が失敗しました。(%d)\n",flag);
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/Makefile buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/Makefile
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/Makefile	2014-05-22 13:46:33.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/Makefile	2015-10-14 10:05:31.020151900 +0900
***************
*** 12,17 ****
--- 12,18 ----
  LIB= -ldl -lpthread
  
  SRCS= kensa.c led_kensa.c vpif_lcd.c macwrite.c eth0.c wlan0.c ts_kensa.c storage.c
+ SERVER_SRCS= kensa-server.c
  
  all: $(SRCS)
  ifndef KERNEL_HEADERS
***************
*** 19,26 ****
  	@echo "\"KERNEL_HEADERS\" should point to the Kernel headers directory. Try \"make KERNEL_HEADERS=<kernel header directory>\""
  else
  	$(CC) -o $(APP) $(SRCS) $(LIB)
  endif
  
  clean:
  	rm -f *.o $(APP)
! 
--- 20,28 ----
  	@echo "\"KERNEL_HEADERS\" should point to the Kernel headers directory. Try \"make KERNEL_HEADERS=<kernel header directory>\""
  else
  	$(CC) -o $(APP) $(SRCS) $(LIB)
+ 	$(CC) -o kensa-server $(SERVER_SRCS) $(LIB)
  endif
  
  clean:
  	rm -f *.o $(APP)
! 	rm -f kensa-server
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/wlan0.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/wlan0.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-1808/samples/kensa/wlan0.c	2014-08-06 21:43:03.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-1808/samples/kensa/wlan0.c	2015-10-20 09:17:22.598225100 +0900
***************
*** 11,18 ****
--- 11,20 ----
  #include <stdlib.h>
  #include <string.h>
  #include <sys/fcntl.h>
+ #include "kensa.h"
  
  //#define _DEBUG
+ #define WLAN_RETRY_CNT	120				/* 2 mins approx */
  
  /* アクセスポイントに接続してネットワークにpingして無線LAN(wlan0)を検査する */
  int wlan0_kensa()
***************
*** 24,37 ****
  	int flag;
  	char *argv_cmd[10];
  	FILE* fp;
! 
  	/* wlan0をアクセスポイント(CMJKENSA11)に接続する */
  	argv_cmd[0] = "/etc/network/wlan-scripts/INFR_WPA2.sh";	// WPA2-PSK(AES)
! 	argv_cmd[1] = "\"CMJKENSA11\"";				// SSID
! 	argv_cmd[2] = "\"Computex0332532901com\"";		// Passphrase
  	argv_cmd[3] = NULL;
  	ShellExecute(argv_cmd[0], argv_cmd);
  
  	/* wlan0をスタティックIPで接続する */
  	argv_cmd[0] = "/sbin/ifup";
  	argv_cmd[1] = "wlan0";
--- 26,47 ----
  	int flag;
  	char *argv_cmd[10];
  	FILE* fp;
! 	int ret;
! 	int retry;
! 	system("/etc/network/wlan-scripts/disconnect_wlan0.sh");
! 	sleep(2);
! 
! _begin:
! 	printf("無線LAN(wlan0)を検査します\n");
! 	ret = 0;
  	/* wlan0をアクセスポイント(CMJKENSA11)に接続する */
  	argv_cmd[0] = "/etc/network/wlan-scripts/INFR_WPA2.sh";	// WPA2-PSK(AES)
! 	argv_cmd[1] = "\""AP_SSID"\"";				// SSID
! 	argv_cmd[2] = "\""AP_PASSWORD"\"";		// Passphrase
  	argv_cmd[3] = NULL;
  	ShellExecute(argv_cmd[0], argv_cmd);
  
+ #if 0
  	/* wlan0をスタティックIPで接続する */
  	argv_cmd[0] = "/sbin/ifup";
  	argv_cmd[1] = "wlan0";
***************
*** 41,49 ****
  		printf("ifup wlan0 に失敗しました。\n");
  		return(1);
  	}
  
  	/* wlan0をが有効になるのを待つ */
! 	printf("wireless AP(CMJKENSA11) ");	fflush(stdout);
  	for( ; ; ) {
  		fp=fopen("/sys/class/net/wlan0/operstate","r");
  #if defined(_DEBUG)
--- 51,81 ----
  		printf("ifup wlan0 に失敗しました。\n");
  		return(1);
  	}
+ #else
+ 	//system("ifup wlan0");
+ 	sleep(3);
+ #endif
+ 	printf("Waiting for wlan0 to connect to AP("AP_SSID")...\n");
+ 	/* wait until wlan0 gets connected */
+ 	retry = 0;
+ 	while(retry < WLAN_RETRY_CNT) {
+ 		if(!system("iwconfig wlan0 | grep "AP_SSID))
+ 		{
+ 			break;
+ 		}
+ 		printf(".");	fflush(stdout);
+ 		retry++;
+ 		sleep(1);
+ 	}
+ 
+ 	if(retry == WLAN_RETRY_CNT) {
+ 		printf("wlan0 couldn't connect to AP\n");
+ 		ret = 1;
+ 		goto _out;
+ 	}
  
  	/* wlan0をが有効になるのを待つ */
! 	printf("wireless AP("AP_SSID") ");	fflush(stdout);
  	for( ; ; ) {
  		fp=fopen("/sys/class/net/wlan0/operstate","r");
  #if defined(_DEBUG)
***************
*** 61,90 ****
  				break;
  			}
  		}
- 		sleep(1);
  		printf(".");	fflush(stdout);
  	}
  	printf("connect.\n");
  
  	/* routeが確認できるまで待つ */
  	system("route");
! 
  	/* wlan0でpingする */
  	argv_cmd[0] = "/bin/ping";
  	argv_cmd[1] = "-I";
  	argv_cmd[2] = "wlan0";
  	argv_cmd[3] = "-c";
  	argv_cmd[4] = "10";
! 	argv_cmd[5] = "192.168.0.200";	/* AP(KENSA11) IP address */
  	argv_cmd[6] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ping -I wlan0 -c 10 192.168.0.200 に失敗しました。\n");
! 		return(1);
  	}
! 	system("ifdown wlan0");
! 
! 
! 	return 0;
  }
  
--- 93,135 ----
  				break;
  			}
  		}
  		printf(".");	fflush(stdout);
+ 		sleep(1);
  	}
  	printf("connect.\n");
  
  	/* routeが確認できるまで待つ */
  	system("route");
! 	sleep(2);
! #if 0
  	/* wlan0でpingする */
  	argv_cmd[0] = "/bin/ping";
  	argv_cmd[1] = "-I";
  	argv_cmd[2] = "wlan0";
  	argv_cmd[3] = "-c";
  	argv_cmd[4] = "10";
! 	argv_cmd[5] = SERVER_WLAN0_IP_ADDR;	/* AP IP address */
  	argv_cmd[6] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ping -I wlan0 -c 10 192.168.0.200 に失敗しました。\n");
! 		ret = 1;
! 		goto _out;
  	}
! #else
! 	ret = iperf_test("wlan0", SERVER_WLAN0_IP_ADDR, CLIENT_WLAN0_IP_ADDR, IPERF_WLAN_SEND_MIN_SPEED, IPERF_WLAN_RECV_MIN_SPEED);
! #endif
! _out:
! 	//system("ifdown wlan0"); // dono use this - leads to Segmentatio nfault in kernel sometimes
! 	system("/etc/network/wlan-scripts/disconnect_wlan0.sh");
! 	sleep(2);
! 	if(ret) {
! 		if( !kensa_yes_no("\nRetry test? [Y/N] : ")) {
! 			goto _begin;
! 		}
! 		on_error(ret, "無線LAN(wlan0), SDIOの検査を途中で終了しました！！!\n");
! 	}
! 	
! 	return ret;
  }
  
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/eth0.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/eth0.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/eth0.c	2013-12-25 21:06:28.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/eth0.c	2015-10-20 09:34:36.794215500 +0900
***************
*** 13,28 ****
  #include <sys/fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  
! /* ネットワークにpingして有線LAN(eth0)を検査する */
  int eth0_kensa()
  {
  	unsigned int i;
- 	char buf[256];
  	int flag;
  	char *argv_cmd[10];
  	struct stat st;
! 
  	/* eth0を固定IPで再接続する */
  	for( i = 0 ; ; i++ ) {
  		argv_cmd[0] = "/sbin/ifup";
--- 13,240 ----
  #include <sys/fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include "kensa.h"
  
! int get_id(char *str, int max_index, int *id)
! {
! 	int i, br_index;
! 
! 	for(i=max_index; i>0 && str[i] != ']'; i--);
! 	if(i<=0)
! 	{
! 		printf("Couldn't find ']' while searching for transfer ID\n");
! 		return -1;
! 	}
! 	br_index = i;
! 	str[br_index] = 0;	/* replace ] with NULL */
! 
! 	for(i--; i>=0 && str[i] != '[' && str[i] != ' '; i--);
! 	if(i<=0)
! 	{
! 		printf("Couldn't find '[' while searching for transfer ID\n");
! 		return -1;
! 	}
! 	/* Get ID */
! 	*id = atoi(&str[i+1]);
! 	str[br_index] = ']';	/* restore ] */
! 	return 0;
! 
! }
! 
! int get_transfer_id(char *buf, char *ip, int *id)
! {
! 	char *s;
! 	char str[50];
! 	int sendspeed, rcvspeed, filesize;
! 	int s_speed, r_speed;
! 	double send_bps, rcv_bps;
! 	
! 	sprintf(str, "%s port 5001", ip);
! 	printf("Searching string - \"%s\"\n", str);
! 	s = strstr(buf, str);
! 	if(!s)
! 	{
! 		printf("Not found\n", str);
! 		return -1;
! 	}
! 
! 	return get_id(buf, s-buf, id);
! }
! 
! int get_speed(char *buf, int transfer_id, double *speed_bps, char *str)
! {
! 	char *s;
! 	char *start;
! 	int id;
! 	char *end_s;
! 	start = buf;
! 	while(1)
! 	{
! 		if((s=strstr(start, str)) == 0)
! 			return -1;
! 		/* check ID */
! 		if(get_id(buf, s-buf, &id))
! 			return -1;
! 		if(id != transfer_id)
! 		{
! 			start = s + 5;
! 			printf("Ignoring found ID %d \n", id);
! 			continue;
! 		}
! 		printf("Transfer ID %d found\n", transfer_id);
! 
! 		/* The speed is indicated in the previous value */
! 		for(s--; s>=buf && *s==' '; s--);
! 		if(s < buf)
! 		{
! 			printf("Couldn't find ending SPACE\n");
! 			return -1;
! 		}
! 		end_s = s + 1;
! 		*end_s = 0;		/* replace space by NULL */
! 		for(s--; s>=buf && *s!=' '; s--);
! 		if(s < buf)
! 		{
! 			printf("Couldn't find starting SPACE\n");
! 			return -1;
! 		}
! 		s++;
! 		printf("Got speed %s\n", s);
! 		*speed_bps = atof(s);
! 		*end_s = ' ';	/* restore the space */
! 		return 0;
! 	}
! }
! 
! int get_transfer_speed(char *buf, int transfer_id, int *speed_bps)
! {
! 	double bps;
! 	if(!get_speed(buf, transfer_id, &bps, "Mbits/sec"))
! 	{
! 		/* convert to Kilo bytes */
! 		*speed_bps = bps * 1000;
! 		return 0;
! 	}
! 
! 	if(!get_speed(buf, transfer_id, &bps, "Kbits/sec"))
! 	{
! 		*speed_bps = bps;
! 		return 0;
! 	}
! 	printf("Error: iperf NG - Speed not in Mbits/sec or Kbits/sec. Probably very slow\n");
! 	return -1;
! }
! 
! int iperf_test(char *dev, char *serveraddr, char *clientaddr, int min_send_speed, int min_recv_speed)
! {
! 	int ret = 0;
! 	int fd;
! 	struct stat st;
! 	char *buf;
! 	char cmd[100];
! 	int sendspeed, rcvspeed, filesize;
! 	int send_id, recv_id;
! 	printf("running iperf (%s)...\n", dev);
! 	
! 	sprintf(cmd, "iperf -c %s -d > " IPERF_LOG_FILE, serveraddr);
! 	if(system(cmd))
! 	{
! 		printf("Error: iperf failed\n");
! 		return 1;
! 	}
! 	printf("iperf output: \n");
! 	system("cat " IPERF_LOG_FILE);
! 	printf("\n");
! 	/* get the file length */
! 	stat(IPERF_LOG_FILE, &st);
! 	filesize = st.st_size;
! 	if(filesize == 0)
! 	{
! _err1:
! 		printf("Error: Couldn't determine iperf speed\n");
! 		return 1;
! 	}
! 	fd = open(IPERF_LOG_FILE, O_RDONLY);
! 	if( fd < 0 )
! 	{
! _err2:
! 		printf("Error opening "IPERF_LOG_FILE"\n");
! 		return 1;
! 	}
! 	buf = malloc(filesize);
! 	/* read the file in one go */
! 	if(read(fd, buf, filesize) != filesize)
! 	{
! _err3:
! 		printf("Error reading "IPERF_LOG_FILE"\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	/* get the transfer IDs - search for string "<ip> port 5001" */
! 	if(get_transfer_id(buf, serveraddr, &send_id))
! 	{
! 		printf("Failed to get send ID\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("SEND ID : %d\n", send_id);
! 	if(get_transfer_id(buf, clientaddr, &recv_id))
! 	{
! 		printf("Failed to get receive ID\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("RECEIVE ID : %d\n", recv_id);
! 	printf("Retrieving send speed - ID %d\n", send_id);
! 	if(get_transfer_speed(buf, send_id, &sendspeed))
! 	{
! 		printf("Failed to get send speed\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("Send speed: %d Kbps\n", sendspeed);
! 	printf("Retrieving receive speed - ID %d\n", recv_id);
! 	if(get_transfer_speed(buf, recv_id, &rcvspeed))
! 	{
! 		printf("Failed to get send speed\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	
! 	printf("Receive speed: %d Kbps\n", rcvspeed);
! 
! 	printf("\nSend speed: %d Kbps Receive speed: %d Kbps\n", sendspeed, rcvspeed);
! 	if((sendspeed < 600 || rcvspeed < 600) 
! 			|| ((sendspeed < min_send_speed) || (rcvspeed < min_recv_speed))
! 				&& ((sendspeed+rcvspeed) < (min_send_speed+min_recv_speed)))
! 	{
! 		printf("Error: iperf NG - Very slow\nSend speed=%d Kbps (expected > %d Kbps)\n"
! 					"receive speed=%d Kbps (expected > %d Kbps)\n",
! 							sendspeed, min_send_speed, rcvspeed, min_recv_speed);
! 		ret = 1;
! 	}
! 
! _failed:
! 	free(buf);
! 	close(fd);
! 	return ret;
! }
! 
! /* ネットワークにiperfして有線LAN(eth0)を検査する */
  int eth0_kensa()
  {
  	unsigned int i;
  	int flag;
  	char *argv_cmd[10];
+ 	int ret;
+ 	int count;
  	struct stat st;
! 	char buf[5];
! 	int fd, r;
! _begin:
! 	printf("有線LAN(eth0)を検査します\n");
! 	ret= 0;
! #if 0
  	/* eth0を固定IPで再接続する */
  	for( i = 0 ; ; i++ ) {
  		argv_cmd[0] = "/sbin/ifup";
***************
*** 34,40 ****
  			break;
  		}
  		if( 120 < i ) {
! 			printf("ifconfig eth0 192.168.11.100 up に失敗しました。\n");
  			return(1);
  		}
  		sleep(1);
--- 246,252 ----
  			break;
  		}
  		if( 120 < i ) {
! 			printf("ifup eth0 に失敗しました。\n");
  			return(1);
  		}
  		sleep(1);
***************
*** 56,63 ****
  		printf("ping -I eth0 -c 10 192.168.0.200 に失敗しました。\n");
  		return(1);
  	}
! 	system("ifconfig eth0 down");
! 
  	return 0;
  }
  
--- 268,311 ----
  		printf("ping -I eth0 -c 10 192.168.0.200 に失敗しました。\n");
  		return(1);
  	}
! 	system("ifdown eth0");
  	return 0;
+ #else
+ 	system("ifdown eth0");
+ 	sleep(1);
+ 	system("ifup eth0");
+ 	system("ifconfig eth0 "CLIENT_ETH0_IP_ADDR" up");
+ 	printf("Waiting for eth0...\n");
+ 	count = 0;
+ 	while(count < (ETHLINK_TO*10))
+ 	{
+ 		if(!system("ifconfig eth0 | grep \"UP BROADCAST RUNNING\""))
+ 			break;
+ 		usleep(100000);
+ 		count++;
+ 		if(count%10 == 0)
+ 		{
+ 			printf(".");
+ 			fflush(stdout);
+ 		}
+ 	}
+ 	if(count == (ETHLINK_TO*10))
+ 	{
+ 		printf("eth0 link-up timeout\n");
+ 		goto _done;
+ 	}
+ 	/* routeが確認出きるまで待つ */
+ 	sleep(2);
+ 	ret = iperf_test("eth0", SERVER_ETH0_IP_ADDR, CLIENT_ETH0_IP_ADDR, IPERF_SEND_MIN_SPEED, IPERF_RECV_MIN_SPEED);
+ 	system("ifdown eth0");
+ 	if(ret) {
+ _done:
+ 		if( !kensa_yes_no("\nRetry test? [Y/N] : ")) {
+ 			goto _begin;
+ 		}
+ 		on_error(ret, "有線LAN(eth0)の検査を途中で終了しました！！!\n");
+ 	}
+ 	return ret;
+ #endif
  }
  
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/kensa.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/kensa.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/kensa.c	2015-01-20 15:30:02.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/kensa.c	2015-10-14 10:05:31.020151900 +0900
***************
*** 9,40 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <signal.h>
! #if 0
! #include <string.h>
! #include <sys/fcntl.h>
! #include <sys/ioctl.h>
! #include <sys/time.h>
! #endif
  
  #include "../../../common/samples/common/Shell_execute.c"
  
  int kensa_yes_no(const char *message)
  {
! 	char dummy;
! 
  	printf(message);
  	while(1){
! 		scanf("%c[ynYN]", &dummy);
! 		(void)getchar();	// '\n'の読み捨て
! 		if( toupper(dummy) == 'Y' ) {
! 			break;
! 		} else if( toupper(dummy) == 'N' ) {
  			return 1;
  		}
  	}
- 	return 0;
  }
  
  
  static void sig(int sig)
  {
--- 9,52 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <signal.h>
! #include "kensa.h"
  
  #include "../../../common/samples/common/Shell_execute.c"
  
  int kensa_yes_no(const char *message)
  {
! 	char ch;
  	printf(message);
  	while(1){
! 		scanf(" %c", &ch);
! 		getchar();		/* lose the Enter key */
! 		switch(ch)
! 		{
! 		case 'N':
! 		case 'n':
  			return 1;
+ 		case 'Y':
+ 		case 'y':
+ 			return 0;
+ 		default:
+ 			printf("無効な入力、再試行してください。。。\n");
  		}
  	}
  }
  
+ void close_app(int ret)
+ {
+ 	exit(ret);
+ }
+ 
+ void on_error(int ret, char *msg)
+ {
+ 	if(kensa_yes_no("続行しますか？(Y/N)"))
+ 	{
+ 		printf(msg);
+ 		close_app(ret);
+ 	}
+ }
  
  static void sig(int sig)
  {
***************
*** 63,68 ****
--- 75,87 ----
  	signal(SIGINT, sig);
  	signal(SIGTERM, sig);
  
+ 	system("killall vpif_cam_app");
+ 	system("killall httpd");
+ 	system("killall udhcpc");
+ 	system("killall avahi-daemon");
+ 	system("killall wpa_supplicant");
+ 	system("killall hostapd");
+ 	system("killall iperf");
  
  	printf("\nボードのレビジョンは？\n");
  	if( 0 == kensa_yes_no("\nRev.2-0以降ならYを、以前ならNを入力してください [Y/N]: ") ) {
***************
*** 70,89 ****
  	} else {
  		rev = 0;
  	}
- 
- 
  	printf("検査に必要な機器をすべて接続してください。\n");
  	printf("● CKB-3352ボード\n");
  	printf("● CKB-LCD-01ボードとCKB-3352ボードをフラットケーブル1本で接続\n");
  	if( !lcd5only ) {
  		if( rev==0 ) {
  			printf("● LCDディスプレイに接続するDVI(microHDMI)ケーブル\n");
  		}
  		printf("● CMJ-100 1個\n");
! 		printf("● LANケーブル(検査用無線LANルータ)\n");
  		printf("● microSDカード(32MB以上) 1枚\n");
  		printf("● USBメモリ(32MB以上) 2個\n");
  	}
  	printf("● AC電源ケーブル\n\n");
  	printf("すべての機器が接続されているか確認して検査を開始します!\nなんらかのキーを押してください。");
  	(void)getchar();	// キー入力まち
--- 89,109 ----
  	} else {
  		rev = 0;
  	}
  	printf("検査に必要な機器をすべて接続してください。\n");
  	printf("● CKB-3352ボード\n");
+ 	printf("● AC電源ケーブル\n");
  	printf("● CKB-LCD-01ボードとCKB-3352ボードをフラットケーブル1本で接続\n");
+ 	
  	if( !lcd5only ) {
  		if( rev==0 ) {
  			printf("● LCDディスプレイに接続するDVI(microHDMI)ケーブル\n");
  		}
  		printf("● CMJ-100 1個\n");
! 		printf("● LANケーブルで親機と接続\n");
  		printf("● microSDカード(32MB以上) 1枚\n");
  		printf("● USBメモリ(32MB以上) 2個\n");
  	}
+ 	printf("● UART1 シリアルケーブルで親機と接続\n");
  	printf("● AC電源ケーブル\n\n");
  	printf("すべての機器が接続されているか確認して検査を開始します!\nなんらかのキーを押してください。");
  	(void)getchar();	// キー入力まち
***************
*** 121,137 ****
  		fprintf(fd, "auto lo wlan0 eth0\n");
  		fprintf(fd, "iface lo inet loopback\n");
  		fprintf(fd, "iface eth0 inet static\n");
! 		fprintf(fd, "  address 192.168.0.110\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.0.0\n");
! 		fprintf(fd, "  broadcast 192.168.0.255\n");
! 		fprintf(fd, "  gateway 192.168.0.200\n");
  		fprintf(fd, "iface wlan0 inet static\n");
! 		fprintf(fd, "  address 192.168.0.111\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.0.0\n");
! 		fprintf(fd, "  broadcast 192.168.0.255\n");
! 		fprintf(fd, "  gateway 192.168.0.200\n");
  		fclose(fd);
  
  		printf("######################################################\n");
--- 141,157 ----
  		fprintf(fd, "auto lo wlan0 eth0\n");
  		fprintf(fd, "iface lo inet loopback\n");
  		fprintf(fd, "iface eth0 inet static\n");
! 		fprintf(fd, "  address "CLIENT_ETH0_IP_ADDR"\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.2.0\n");
! 		fprintf(fd, "  broadcast 192.168.2.255\n");
! 		fprintf(fd, "  gateway "SERVER_ETH0_IP_ADDR"\n");
  		fprintf(fd, "iface wlan0 inet static\n");
! 		fprintf(fd, "  address "CLIENT_WLAN0_IP_ADDR"\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.3.0\n");
! 		fprintf(fd, "  broadcast 192.168.3.255\n");
! 		fprintf(fd, "  gateway "SERVER_WLAN0_IP_ADDR"\n");
  		fclose(fd);
  
  		printf("######################################################\n");
***************
*** 146,161 ****
  		printf("有線LANコネクタと検査用ルータが接続されている必要があります\n");
  		printf("######################################################\n");
  		if( eth0_kensa() ) {
- 			printf("有線LAN(eth0)の検査を途中で終了しました！！!\n");
- 			exit(1);
  		}
  		printf("######################################################\n");
  		printf("無線LAN(wlan0), SDIOを検査します\n");
  		printf("CM-J100が接続されている必要があります\n");
  		printf("######################################################\n");
  		if( wlan0_kensa() ) {
- 			printf("無線LAN(wlan0), SDIOの検査を途中で終了しました！！!\n");
- 			exit(1);
  		}
  
  		printf("######################################################\n");
--- 166,177 ----
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/kensa.h buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/kensa.h
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/kensa.h	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/kensa.h	2015-10-20 09:35:13.955424800 +0900
***************
*** 0 ****
--- 1,35 ----
+ /*
+  * kensa.h
+  *
+  * CKB Kensa program
+  *
+  * Copyright 2012 Computex Co.,Ltd.
+  *
+  */
+ 
+ #ifndef _KENSA_H_
+ #define _KENSA_H_
+ 
+ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+ 
+ #define SERVER_ETH0_IP_ADDR  "192.168.2.100"
+ #define CLIENT_ETH0_IP_ADDR  "192.168.2.200"
+ 
+ #define SERVER_WLAN0_IP_ADDR	"192.168.3.100"
+ #define CLIENT_WLAN0_IP_ADDR	"192.168.3.200"
+ 
+ #define AP_SSID			"CKBKENSA3"
+ #define AP_PASSWORD		"Computex3"
+ 
+ #define IPERF_LOG_FILE			"/tmp/iperf.log"
+ #define IPERF_TASK_FILE			"/tmp/iperf.task"
+ 
+ 
+ #define IPERF_SEND_MIN_SPEED	100000
+ #define IPERF_RECV_MIN_SPEED	75000
+ 
+ #define IPERF_WLAN_SEND_MIN_SPEED	5000
+ #define IPERF_WLAN_RECV_MIN_SPEED	8000
+ 
+ #define ETHLINK_TO				60		/* secs */
+ #endif
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/kensa-server.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/kensa-server.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/kensa-server.c	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/kensa-server.c	2015-10-19 09:59:20.393198300 +0900
***************
*** 0 ****
--- 1,190 ----
+ /*
+  * kensa.c
+  *
+  * CKB-3352 Kensa server program
+  *
+  * Copyright 2013 Computex Co.,Ltd.
+  *
+  */
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <signal.h>
+ #include <sys/fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include "kensa.h"
+ #include <termios.h>
+ 
+ struct termios orig_tio, new_tio;
+ void saveOrigTTYsettings()
+ {
+ 	 tcgetattr(0, &orig_tio);
+ }
+ void restoreOrigTTYsettings()
+ {
+ 	 tcsetattr(0, TCSANOW, &orig_tio);
+ }
+ 
+ _Bool kbhit(u_char *ch)
+ {
+     return read(0,ch,1)?1:0;
+ }
+ 
+ void setKbhitMode()
+ {
+ 	memcpy(&new_tio, &orig_tio, sizeof(struct termios));
+ 	new_tio.c_cc[VMIN]=0;
+     new_tio.c_lflag &= ~ICANON;
+     new_tio.c_lflag &= ~ECHO;
+     new_tio.c_lflag &= ~ISIG;
+ //    new_tio.c_cc[VMIN] = 1;
+     new_tio.c_cc[VTIME] = 0;
+     tcsetattr(0, TCSANOW, &new_tio);
+ }
+ 
+ int kensa_yes_no(const char *message)
+ {
+ 	char ch;
+ 	printf(message);
+ 	while(1){
+ 		scanf(" %c", &ch);
+ 		getchar();		/* lose the Enter key */
+ 		switch(ch)
+ 		{
+ 		case 'N':
+ 		case 'n':
+ 			return 1;
+ 		case 'Y':
+ 		case 'y':
+ 			return 0;
+ 		default:
+ 			printf("無効な入力、再試行してください。。。\n");
+ 		}
+ 	}
+ }
+ 
+ 
+ static void sig(int sig)
+ {
+ 	fflush(stderr);
+ 	printf("signal %d caught\n", sig);
+ 	fflush(stdout);
+ 	exit(1);
+ }
+ 
+ void help()
+ {
+ 	printf("Usage: kensa-server\n");
+ }
+ 
+ /* main() */
+ int main(int argc, char* argv[])
+ {
+ 	int lcd5only = 0;	// 1=LCDボードの検査を行う
+ 	int flag;
+ 	FILE *fd;
+ 	char *argv_cmd[10];
+ 	int rev;			// 0=Rev.A以前、1=Rev.B以降
+ 	struct stat st;
+ 	int filesize;
+ 	char *buf;
+ 	int bufsize = 0;
+ 	u_char ch;
+ #if 0
+ 	/* signal handler */
+ 	signal(SIGSEGV, sig);
+ 	signal(SIGINT, sig);
+ 	signal(SIGTERM, sig);
+ #endif
+ 	system("killall vpif_cam_app");
+ 	system("killall httpd");
+ 	system("killall udhcpc");
+ 	system("killall avahi-daemon");
+ 	system("killall wpa_supplicant");
+ 	system("killall hostapd");
+ 	
+ 	printf("**** Kensa server application\nTerminating any running iperf...");
+ 	system("killall iperf");
+ 	sleep(2);
+ 	/* 検査用のネットワーク設定に変更する */
+ 	system("ifdown eth0");
+ 	system("ifconfig eth0 down");
+ 	system("ifdown wlan0");
+ 
+ 	fd=fopen("/etc/network/interfaces","w");
+ 	fprintf(fd, "auto lo wlan0 eth0\n");
+ 	fprintf(fd, "iface lo inet loopback\n");
+ 	fprintf(fd, "iface eth0 inet static\n");
+ 	fprintf(fd, "  address "SERVER_ETH0_IP_ADDR"\n");
+ 	fprintf(fd, "  netmask 255.255.255.0\n");
+ 	fprintf(fd, "  network 192.168.2.0\n");
+ 	fprintf(fd, "  broadcast 192.168.2.255\n");
+ 	fprintf(fd, "  gateway "SERVER_ETH0_IP_ADDR"\n");
+ 	fprintf(fd, "iface wlan0 inet static\n");
+ 	fprintf(fd, "  address "SERVER_WLAN0_IP_ADDR"\n");
+ 	fprintf(fd, "  netmask 255.255.255.0\n");
+ 	fprintf(fd, "  network 192.168.3.0\n");
+ 	fprintf(fd, "  broadcast 192.168.3.255\n");
+ 	fprintf(fd, "  gateway "SERVER_WLAN0_IP_ADDR"\n");
+ 	fclose(fd);
+ 
+ 	system("ifup eth0");
+ 	system("ifconfig eth0 "SERVER_ETH0_IP_ADDR" up");
+ 	system ("/etc/network/wlan-scripts/HOSTAPD_WPA2.sh n 1 '"AP_SSID"' '"AP_PASSWORD"'");
+ 
+ 	saveOrigTTYsettings();
+ 	setKbhitMode();
+ 	printf("**** Press q to terminate application ****\n");
+ 	while(1)
+ 	{
+ 		if(kbhit(&ch)==1)
+ 		{
+ 			if(ch=='q')
+ 				break;
+ 		}
+ 		system("ps -a | grep \"iperf -s\" | awk '{print $3}' > " IPERF_TASK_FILE);
+ 		system("sync");
+ 		sleep(1);
+ 		/* get the file length */
+ 		stat(IPERF_TASK_FILE, &st);
+ 		filesize = st.st_size;
+ 		if(filesize == 0)
+ 		{
+ 			goto _iperf;
+ 		}
+ 		fd = open(IPERF_TASK_FILE, O_RDONLY);
+ 		if( fd < 0 )
+ 		{
+ 			printf("Error opening "IPERF_TASK_FILE"\n");
+ 			continue;
+ 		}
+ 		if(filesize > bufsize)
+ 		{
+ 			if(bufsize)
+ 				free(buf);
+ 			buf = malloc(filesize);
+ 			bufsize = filesize;
+ 		}
+ 		/* read the file in one go */
+ 		if(read(fd, buf, filesize) != filesize)
+ 		{
+ 			printf("Error reading "IPERF_TASK_FILE"\n");
+ 			close(fd);
+ 			continue;
+ 		}
+ 		close(fd);
+ 		if(!strncmp("iperf", buf, 5))
+ 			continue;
+ _iperf:
+ 		printf("Starting iperf...\n");
+ 		system("iperf -s &");
+ 		printf("iperf started\n");
+ 		sleep(1);
+ 	}
+ 	if(bufsize)
+ 		free(buf);
+ 
+ 	restoreOrigTTYsettings();
+ 	return 0;
+ }
+ 
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/macwrite.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/macwrite.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/macwrite.c	2014-06-16 13:18:53.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/macwrite.c	2015-10-14 10:05:31.024151900 +0900
***************
*** 53,58 ****
--- 53,61 ----
  	printf("有線LANのMACアドレスを設定します。\n");
  	if( buf2[0] == 0x5a ) {
  		printf("現在の設定は %02X:%02X:%02X:%02X:%02X:%02X に設定されています\n", buf2[1], buf2[2], buf2[3], buf2[4], buf2[5], buf2[6]);
+ 		if( 0 != kensa_yes_no("変更しますか？(Y/N)") ) {
+ 			return 0;
+ 		}
  	} else {
  		printf("現在、MACアドレスが設定されていません\n");
  	}
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/Makefile buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/Makefile
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/Makefile	2014-05-22 13:47:59.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/Makefile	2015-10-14 10:05:31.024151900 +0900
***************
*** 12,17 ****
--- 12,18 ----
  LIB= -ldl -lpthread
  
  SRCS= kensa.c led_kensa.c macwrite.c eth0.c wlan0.c ts_kensa.c storage.c dvi.c
+ SERVER_SRCS= kensa-server.c
  
  all: $(SRCS)
  ifndef KERNEL_HEADERS
***************
*** 19,26 ****
  	@echo "\"KERNEL_HEADERS\" should point to the Kernel headers directory. Try \"make KERNEL_HEADERS=<kernel header directory>\""
  else
  	$(CC) -o $(APP) $(SRCS) $(LIB)
  endif
  
  clean:
  	rm -f *.o $(APP)
! 
--- 20,28 ----
  	@echo "\"KERNEL_HEADERS\" should point to the Kernel headers directory. Try \"make KERNEL_HEADERS=<kernel header directory>\""
  else
  	$(CC) -o $(APP) $(SRCS) $(LIB)
+ 	$(CC) -o kensa-server $(SERVER_SRCS) $(LIB)
  endif
  
  clean:
  	rm -f *.o $(APP)
! 	rm -f kensa-server
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/wlan0.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/wlan0.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-3352/samples/kensa/wlan0.c	2014-06-16 13:19:44.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-3352/samples/kensa/wlan0.c	2015-10-20 09:35:35.408462300 +0900
***************
*** 11,18 ****
--- 11,20 ----
  #include <stdlib.h>
  #include <string.h>
  #include <sys/fcntl.h>
+ #include "kensa.h"
  
  //#define _DEBUG
+ #define WLAN_RETRY_CNT	120				/* 2 mins approx */
  
  /* アクセスポイントに接続してネットワークにpingして無線LAN(wlan0)を検査する */
  int wlan0_kensa()
***************
*** 24,49 ****
  	int flag;
  	char *argv_cmd[10];
  	FILE* fp;
! 
  	/* wlan0をアクセスポイント(CMJKENSA11)に接続する */
  	argv_cmd[0] = "/etc/network/wlan-scripts/INFR_WPA2.sh";	// WPA2-PSK(AES)
! 	argv_cmd[1] = "\"CMJKENSA11\"";				// SSID
! 	argv_cmd[2] = "\"Computex0332532901com\"";		// Passphrase
  	argv_cmd[3] = NULL;
  	ShellExecute(argv_cmd[0], argv_cmd);
  
  	/* wlan0をスタティックIPで接続する */
  	argv_cmd[0] = "/sbin/ifup";
  	argv_cmd[1] = "wlan0";
  	argv_cmd[2] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ifup wlan0 に失敗しました。\n");
! 		return(1);
  	}
  
  	/* wlan0をが有効になるのを待つ */
! 	printf("wireless AP(CMJKENSA11) ");	fflush(stdout);
  	for( ; ; ) {
  		fp=fopen("/sys/class/net/wlan0/wireless/link","r");
  #if defined(_DEBUG)
--- 26,84 ----
  	int flag;
  	char *argv_cmd[10];
  	FILE* fp;
! 	int ret;
! 	int retry;
! 	system("/etc/network/wlan-scripts/disconnect_wlan0.sh");
! 	sleep(2);
! 
! _begin:
! 	printf("無線LAN(wlan0)を検査します\n");
! 	ret = 0;
  	/* wlan0をアクセスポイント(CMJKENSA11)に接続する */
  	argv_cmd[0] = "/etc/network/wlan-scripts/INFR_WPA2.sh";	// WPA2-PSK(AES)
! 	argv_cmd[1] = "\""AP_SSID"\"";				// SSID
! 	argv_cmd[2] = "\""AP_PASSWORD"\"";		// Passphrase
  	argv_cmd[3] = NULL;
  	ShellExecute(argv_cmd[0], argv_cmd);
  
+ #if 0
  	/* wlan0をスタティックIPで接続する */
  	argv_cmd[0] = "/sbin/ifup";
  	argv_cmd[1] = "wlan0";
  	argv_cmd[2] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
+ #if 0
  		printf("ifup wlan0 に失敗しました。\n");
! 		ret = 1;
! 		goto _out;
! #endif
! 	}
! #else
! 	//system("ifup wlan0");
! 	sleep(3);
! #endif
! 	printf("Waiting for wlan0 to connect to AP("AP_SSID")...\n");
! 	/* wait until wlan0 gets connected */
! 	retry = 0;
! 	while(retry < WLAN_RETRY_CNT) {
! 		if(!system("iwconfig wlan0 | grep "AP_SSID))
! 		{
! 			break;
! 		}
! 		printf(".");	fflush(stdout);
! 		retry++;
! 		sleep(1);
! 	}
! 
! 	if(retry == WLAN_RETRY_CNT) {
! 		printf("wlan0 couldn't connect to AP\n");
! 		ret = 1;
! 		goto _out;
  	}
  
  	/* wlan0をが有効になるのを待つ */
! 	printf("wireless AP("AP_SSID") ");	fflush(stdout);
  	for( ; ; ) {
  		fp=fopen("/sys/class/net/wlan0/wireless/link","r");
  #if defined(_DEBUG)
***************
*** 61,90 ****
  				break;
  			}
  		}
- 		sleep(1);
  		printf(".");	fflush(stdout);
  	}
  	printf("connect.\n");
  
  	/* routeが確認できるまで待つ */
  	system("route");
! 
  	/* wlan0でpingする */
  	argv_cmd[0] = "/bin/ping";
  	argv_cmd[1] = "-I";
  	argv_cmd[2] = "wlan0";
  	argv_cmd[3] = "-c";
  	argv_cmd[4] = "10";
! 	argv_cmd[5] = "192.168.0.200";	/* AP(KENSA11) IP address */
  	argv_cmd[6] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ping -I wlan0 -c 10 192.168.0.200 に失敗しました。\n");
! 		return(1);
  	}
! 	system("ifdown wlan0");
! 
! 
! 	return 0;
  }
  
--- 96,138 ----
  				break;
  			}
  		}
  		printf(".");	fflush(stdout);
+ 		sleep(1);
  	}
  	printf("connect.\n");
  
  	/* routeが確認できるまで待つ */
  	system("route");
! 	sleep(2);
! #if 0
  	/* wlan0でpingする */
  	argv_cmd[0] = "/bin/ping";
  	argv_cmd[1] = "-I";
  	argv_cmd[2] = "wlan0";
  	argv_cmd[3] = "-c";
  	argv_cmd[4] = "10";
! 	argv_cmd[5] = SERVER_WLAN0_IP_ADDR;	/* AP IP address */
  	argv_cmd[6] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ping -I wlan0 -c 10 192.168.0.200 に失敗しました。\n");
! 		ret = 1;
! 		goto _out;
  	}
! #else
! 	ret = iperf_test("wlan0", SERVER_WLAN0_IP_ADDR, CLIENT_WLAN0_IP_ADDR, IPERF_WLAN_SEND_MIN_SPEED, IPERF_WLAN_RECV_MIN_SPEED);
! #endif
! _out:
! 	//system("ifdown wlan0"); // dono use this - leads to Segmentatio nfault in kernel sometimes
! 	system("/etc/network/wlan-scripts/disconnect_wlan0.sh");
! 	sleep(2);
! 	if(ret) {
! 		if( !kensa_yes_no("\nRetry test? [Y/N] : ")) {
! 			goto _begin;
! 		}
! 		on_error(ret, "無線LAN(wlan0), SDIOの検査を途中で終了しました！！!\n");
! 	}
! 	
! 	return ret;
  }
  
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/bd_rev.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/bd_rev.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/bd_rev.c	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/bd_rev.c	2015-10-16 13:09:15.418255300 +0900
***************
*** 0 ****
--- 1,160 ----
+ /*
+  * eth0.c
+  *
+  * CKB Kensa program
+  *
+  * Copyright 2012 Computex Co.,Ltd.
+  *
+  */
+ 
+ #include <stdio.h>
+ #include <fcntl.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <sys/fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/ioctl.h>
+ #include <linux/types.h>
+ #include <errno.h>
+ #include <ctype.h>
+ #include "kensa.h"
+ #include <termios.h>
+ 
+ #define EEPROM			"/sys/bus/i2c/drivers/at24/2-0051/eeprom"
+ 
+ #define BOARD_REV_OFFSET 40
+ unsigned char board_rev_header[2] = {0xA5, 0xDE};
+ 
+ struct termios orig_tio, new_tio;
+ void saveOrigTTYsettings()
+ {
+ 	 tcgetattr(0, &orig_tio);
+ }
+ 
+ void setKbhitMode()
+ {
+ 	memcpy(&new_tio, &orig_tio, sizeof(struct termios));
+ 	new_tio.c_cc[VMIN]=0;
+     new_tio.c_lflag &= ~ICANON;
+     new_tio.c_lflag &= ~ECHO;
+     new_tio.c_lflag &= ~ISIG;
+ //    new_tio.c_cc[VMIN] = 1;
+     new_tio.c_cc[VTIME] = 0;
+     tcsetattr(0, TCSANOW, &new_tio);
+ }
+ 
+ 
+ unsigned char read_revision()
+ {
+ 	int fd, i;
+ 	unsigned char buf[3];
+ 	unsigned char val;
+ 
+ 	fd = open(EEPROM, O_RDONLY);
+ 	if( fd == -1 ) {
+ 		printf("Error: Open of "EEPROM" failed: %s\n", strerror(errno));
+ 		return 1;
+ 	}
+ 	lseek(fd, BOARD_REV_OFFSET, SEEK_SET);
+ 	/* read 3 bytes */
+ 	if(read(fd, buf, 3) != 3) {
+ 		printf("Error: "EEPROM" read failed: %s\n", strerror(errno));
+ 		val = 2;
+ 		goto _out;
+ 	}
+ 	for(i=0; i<2; i++)
+ 	{
+ 		if(buf[i] != board_rev_header[i])
+ 		{
+ 			printf("Board revision not found\n");
+ 			val = 3;
+ 			goto _out;
+ 		}
+ 	}
+ 	val = buf[i];
+ _out:
+ 	close(fd);
+ 	return val;
+ }
+ 
+ int write_revision(unsigned char rev)
+ {
+ 	int fd, i;
+ 	unsigned char buf[3];
+ 	int ret = 0;
+ 	fd = open(EEPROM, O_RDWR);
+ 	if( fd == -1 ) {
+ 		printf("Error: Open of "EEPROM" failed: %s\n", strerror(errno));
+ 		return 1;
+ 	}
+ 	for(i=0; i<2; i++)
+ 		buf[i] = board_rev_header[i];
+ 	buf[i] = rev;
+ 
+ 	lseek(fd, BOARD_REV_OFFSET, SEEK_SET);
+ 	/* write the header and value */
+ 	if(write(fd, buf, 3) != 3) {
+ 		printf("Error: "EEPROM" write failed: %s\n", strerror(errno));
+ 		ret = 2;
+ 	}
+ _out:
+ 	close(fd);
+ 	if(!ret)
+ 	{
+ 		/* read and confirm */
+ 		if(read_revision() == rev)
+ 		{
+ 			printf("ボードのリビジョンを書きました - Revision-%c です。\n", rev);
+ 			printf("再起動してください。。。\n");
+ 			/* hang */
+ 			saveOrigTTYsettings();
+ 			setKbhitMode();
+ 			while(1);
+ 		}
+ 		printf("Error: "EEPROM" read value mismatch after write\n");
+ 		ret = 3;
+ 	}
+ 	return ret;
+ }
+ 
+ /* ネットワークにpingして有線LAN(eth0)を検査する */
+ void board_revision()
+ {
+ 	unsigned int i;
+ 	int flag;
+ 	unsigned char rev;
+ 	int ret;
+ 
+ _begin:
+ 	printf("Reading board revision\n");
+ 
+ 	rev = read_revision();
+ 	if(rev >= 'A' && rev <= 'D')
+ 	{
+ 		printf("ボードのリビジョンは Revision-%c です。\n", rev);
+ 		if( 0 != kensa_yes_no("変更しますか?(Y/N)") ) {
+ 			return;
+ 		}
+ 	}
+ 	printf("ボードのリビジョンを続けて設定してください。(A/B/C/D)\n");
+ 	while(1) {
+ 		rev = getchar();
+ 		if(!isalpha(rev))
+ 			continue;
+ 		rev = toupper(rev);
+ 		if(rev >= 'A' && rev <= 'D')
+ 			break;
+ 	}
+ 	(void)getchar();	// '\n'の読み捨て
+ 	if(write_revision(rev))
+ 	{
+ 		if( !kensa_yes_no("\nリトライしますか? [Y/N] : ")) {
+ 			goto _begin;
+ 		}
+ 		on_error(ret, "ボードのリビジョンをかく中で終了しました！！!\n");
+ 	}
+ }
+ 
+ 
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/eth0.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/eth0.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/eth0.c	2013-12-25 21:03:07.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/eth0.c	2015-10-20 09:39:25.210213000 +0900
***************
*** 13,28 ****
  #include <sys/fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  
! /* ネットワークにpingして有線LAN(eth0)を検査する */
  int eth0_kensa()
  {
  	unsigned int i;
- 	char buf[256];
  	int flag;
  	char *argv_cmd[10];
  	struct stat st;
! 
  	/* eth0を固定IPで再接続する */
  	for( i = 0 ; ; i++ ) {
  		argv_cmd[0] = "/sbin/ifup";
--- 13,240 ----
  #include <sys/fcntl.h>
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include "kensa.h"
  
! int get_id(char *str, int max_index, int *id)
! {
! 	int i, br_index;
! 
! 	for(i=max_index; i>0 && str[i] != ']'; i--);
! 	if(i<=0)
! 	{
! 		printf("Couldn't find ']' while searching for transfer ID\n");
! 		return -1;
! 	}
! 	br_index = i;
! 	str[br_index] = 0;	/* replace ] with NULL */
! 
! 	for(i--; i>=0 && str[i] != '[' && str[i] != ' '; i--);
! 	if(i<=0)
! 	{
! 		printf("Couldn't find '[' while searching for transfer ID\n");
! 		return -1;
! 	}
! 	/* Get ID */
! 	*id = atoi(&str[i+1]);
! 	str[br_index] = ']';	/* restore ] */
! 	return 0;
! 
! }
! 
! int get_transfer_id(char *buf, char *ip, int *id)
! {
! 	char *s;
! 	char str[50];
! 	int sendspeed, rcvspeed, filesize;
! 	int s_speed, r_speed;
! 	double send_bps, rcv_bps;
! 	
! 	sprintf(str, "%s port 5001", ip);
! 	printf("Searching string - \"%s\"\n", str);
! 	s = strstr(buf, str);
! 	if(!s)
! 	{
! 		printf("Not found\n", str);
! 		return -1;
! 	}
! 
! 	return get_id(buf, s-buf, id);
! }
! 
! int get_speed(char *buf, int transfer_id, double *speed_bps, char *str)
! {
! 	char *s;
! 	char *start;
! 	int id;
! 	char *end_s;
! 	start = buf;
! 	while(1)
! 	{
! 		if((s=strstr(start, str)) == 0)
! 			return -1;
! 		/* check ID */
! 		if(get_id(buf, s-buf, &id))
! 			return -1;
! 		if(id != transfer_id)
! 		{
! 			start = s + 5;
! 			printf("Ignoring found ID %d \n", id);
! 			continue;
! 		}
! 		printf("Transfer ID %d found\n", transfer_id);
! 
! 		/* The speed is indicated in the previous value */
! 		for(s--; s>=buf && *s==' '; s--);
! 		if(s < buf)
! 		{
! 			printf("Couldn't find ending SPACE\n");
! 			return -1;
! 		}
! 		end_s = s + 1;
! 		*end_s = 0;		/* replace space by NULL */
! 		for(s--; s>=buf && *s!=' '; s--);
! 		if(s < buf)
! 		{
! 			printf("Couldn't find starting SPACE\n");
! 			return -1;
! 		}
! 		s++;
! 		printf("Got speed %s\n", s);
! 		*speed_bps = atof(s);
! 		*end_s = ' ';	/* restore the space */
! 		return 0;
! 	}
! }
! 
! int get_transfer_speed(char *buf, int transfer_id, int *speed_bps)
! {
! 	double bps;
! 	if(!get_speed(buf, transfer_id, &bps, "Mbits/sec"))
! 	{
! 		/* convert to Kilo bytes */
! 		*speed_bps = bps * 1000;
! 		return 0;
! 	}
! 
! 	if(!get_speed(buf, transfer_id, &bps, "Kbits/sec"))
! 	{
! 		*speed_bps = bps;
! 		return 0;
! 	}
! 	printf("Error: iperf NG - Speed not in Mbits/sec or Kbits/sec. Probably very slow\n");
! 	return -1;
! }
! 
! int iperf_test(char *dev, char *serveraddr, char *clientaddr, int min_send_speed, int min_recv_speed)
! {
! 	int ret = 0;
! 	int fd;
! 	struct stat st;
! 	char *buf;
! 	char cmd[100];
! 	int sendspeed, rcvspeed, filesize;
! 	int send_id, recv_id;
! 	printf("running iperf (%s)...\n", dev);
! 	
! 	sprintf(cmd, "iperf -c %s -d > " IPERF_LOG_FILE, serveraddr);
! 	if(system(cmd))
! 	{
! 		printf("Error: iperf failed\n");
! 		return 1;
! 	}
! 	printf("iperf output: \n");
! 	system("cat " IPERF_LOG_FILE);
! 	printf("\n");
! 	/* get the file length */
! 	stat(IPERF_LOG_FILE, &st);
! 	filesize = st.st_size;
! 	if(filesize == 0)
! 	{
! _err1:
! 		printf("Error: Couldn't determine iperf speed\n");
! 		return 1;
! 	}
! 	fd = open(IPERF_LOG_FILE, O_RDONLY);
! 	if( fd < 0 )
! 	{
! _err2:
! 		printf("Error opening "IPERF_LOG_FILE"\n");
! 		return 1;
! 	}
! 	buf = malloc(filesize);
! 	/* read the file in one go */
! 	if(read(fd, buf, filesize) != filesize)
! 	{
! _err3:
! 		printf("Error reading "IPERF_LOG_FILE"\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	/* get the transfer IDs - search for string "<ip> port 5001" */
! 	if(get_transfer_id(buf, serveraddr, &send_id))
! 	{
! 		printf("Failed to get send ID\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("SEND ID : %d\n", send_id);
! 	if(get_transfer_id(buf, clientaddr, &recv_id))
! 	{
! 		printf("Failed to get receive ID\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("RECEIVE ID : %d\n", recv_id);
! 	printf("Retrieving send speed - ID %d\n", send_id);
! 	if(get_transfer_speed(buf, send_id, &sendspeed))
! 	{
! 		printf("Failed to get send speed\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	printf("Send speed: %d Kbps\n", sendspeed);
! 	printf("Retrieving receive speed - ID %d\n", recv_id);
! 	if(get_transfer_speed(buf, recv_id, &rcvspeed))
! 	{
! 		printf("Failed to get send speed\n");
! 		ret = 1;
! 		goto _failed;
! 	}
! 	
! 	printf("Receive speed: %d Kbps\n", rcvspeed);
! 
! 	printf("\nSend speed: %d Kbps Receive speed: %d Kbps\n", sendspeed, rcvspeed);
! 	if((sendspeed < 600 || rcvspeed < 600) 
! 			|| ((sendspeed < min_send_speed) || (rcvspeed < min_recv_speed))
! 				&& ((sendspeed+rcvspeed) < (min_send_speed+min_recv_speed)))
! 	{
! 		printf("Error: iperf NG - Very slow\nSend speed=%d Kbps (expected > %d Kbps)\n"
! 					"receive speed=%d Kbps (expected > %d Kbps)\n",
! 							sendspeed, min_send_speed, rcvspeed, min_recv_speed);
! 		ret = 1;
! 	}
! 
! _failed:
! 	free(buf);
! 	close(fd);
! 	return ret;
! }
! 
! /* ネットワークにiperfして有線LAN(eth0)を検査する */
  int eth0_kensa()
  {
  	unsigned int i;
  	int flag;
  	char *argv_cmd[10];
+ 	int ret;
+ 	int count;
  	struct stat st;
! 	char buf[5];
! 	int fd, r;
! _begin:
! 	printf("有線LAN(eth0)を検査します\n");
! 	ret= 0;
! #if 0
  	/* eth0を固定IPで再接続する */
  	for( i = 0 ; ; i++ ) {
  		argv_cmd[0] = "/sbin/ifup";
***************
*** 34,40 ****
  			break;
  		}
  		if( 120 < i ) {
! 			printf("ifconfig eth0 192.168.11.100 up に失敗しました。\n");
  			return(1);
  		}
  		sleep(1);
--- 246,252 ----
  			break;
  		}
  		if( 120 < i ) {
! 			printf("ifup eth0 に失敗しました。\n");
  			return(1);
  		}
  		sleep(1);
***************
*** 56,63 ****
  		printf("ping -I eth0 -c 10 192.168.0.200 に失敗しました。\n");
  		return(1);
  	}
! 	system("ifconfig eth0 down");
! 
  	return 0;
  }
  
--- 268,311 ----
  		printf("ping -I eth0 -c 10 192.168.0.200 に失敗しました。\n");
  		return(1);
  	}
! 	system("ifdown eth0");
  	return 0;
+ #else
+ 	system("ifdown eth0");
+ 	sleep(1);
+ 	system("ifup eth0");
+ 	system("ifconfig eth0 "CLIENT_ETH0_IP_ADDR" up");
+ 	printf("Waiting for eth0...\n");
+ 	count = 0;
+ 	while(count < (ETHLINK_TO*10))
+ 	{
+ 		if(!system("ifconfig eth0 | grep \"UP BROADCAST RUNNING\""))
+ 			break;
+ 		usleep(100000);
+ 		count++;
+ 		if(count%10 == 0)
+ 		{
+ 			printf(".");
+ 			fflush(stdout);
+ 		}
+ 	}
+ 	if(count == (ETHLINK_TO*10))
+ 	{
+ 		printf("eth0 link-up timeout\n");
+ 		goto _done;
+ 	}
+ 	/* routeが確認出きるまで待つ */
+ 	sleep(2);
+ 	ret = iperf_test("eth0", SERVER_ETH0_IP_ADDR, CLIENT_ETH0_IP_ADDR, IPERF_SEND_MIN_SPEED, IPERF_RECV_MIN_SPEED);
+ 	system("ifdown eth0");
+ 	if(ret) {
+ _done:
+ 		if( !kensa_yes_no("\nRetry test? [Y/N] : ")) {
+ 			goto _begin;
+ 		}
+ 		on_error(ret, "有線LAN(eth0)の検査を途中で終了しました！！!\n");
+ 	}
+ 	return ret;
+ #endif
  }
  
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/kensa.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/kensa.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/kensa.c	2014-02-10 11:50:31.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/kensa.c	2015-10-20 09:18:04.802224700 +0900
***************
*** 9,40 ****
  #include <stdio.h>
  #include <stdlib.h>
  #include <signal.h>
! #if 0
! #include <string.h>
! #include <sys/fcntl.h>
! #include <sys/ioctl.h>
! #include <sys/time.h>
! #endif
  
  #include "../../../common/samples/common/Shell_execute.c"
  
  int kensa_yes_no(const char *message)
  {
! 	char dummy;
! 
  	printf(message);
  	while(1){
! 		scanf("%c[ynYN]", &dummy);
! 		(void)getchar();	// '\n'の読み捨て
! 		if( toupper(dummy) == 'Y' ) {
! 			break;
! 		} else if( toupper(dummy) == 'N' ) {
  			return 1;
  		}
  	}
- 	return 0;
  }
  
  
  static void sig(int sig)
  {
--- 9,52 ----
  #include <stdio.h>
  #include <stdlib.h>
  #include <signal.h>
! #include "kensa.h"
  
  #include "../../../common/samples/common/Shell_execute.c"
  
  int kensa_yes_no(const char *message)
  {
! 	char ch;
  	printf(message);
  	while(1){
! 		scanf(" %c", &ch);
! 		getchar();		/* lose the Enter key */
! 		switch(ch)
! 		{
! 		case 'N':
! 		case 'n':
  			return 1;
+ 		case 'Y':
+ 		case 'y':
+ 			return 0;
+ 		default:
+ 			printf("無効な入力、再試行してください。。。\n");
  		}
  	}
  }
  
+ void close_app(int ret)
+ {
+ 	exit(ret);
+ }
+ 
+ void on_error(int ret, char *msg)
+ {
+ 	if(kensa_yes_no("続行しますか？(Y/N)"))
+ 	{
+ 		printf(msg);
+ 		close_app(ret);
+ 	}
+ }
  
  static void sig(int sig)
  {
***************
*** 62,67 ****
--- 74,86 ----
  	signal(SIGINT, sig);
  	signal(SIGTERM, sig);
  
+ 	system("killall vpif_cam_app");
+ 	system("killall httpd");
+ 	system("killall udhcpc");
+ 	system("killall avahi-daemon");
+ 	system("killall wpa_supplicant");
+ 	system("killall hostapd");
+ 	system("killall iperf");
  	printf("検査に必要な機器をすべて接続してください。\n");
  	printf("● CKB-RZ/A1Hボード\n");
  	printf("● CKB-LCD-01ボードとCKB-RZ/A1Hボードをフラットケーブル1本で接続\n");
***************
*** 75,80 ****
--- 94,101 ----
  	printf("すべての機器が接続されているか確認して検査を開始します!\nなんらかのキーを押してください。");
  	(void)getchar();	// キー入力まち
  
+ 	board_revision();
+ 	
  	printf("######################################################\n");
  	printf("LED1(赤), LED2(赤)を検査します\n");
  	printf("######################################################\n");
***************
*** 100,105 ****
--- 121,127 ----
  		printf("検査を途中で終了しました！！!\n");
  		exit(1);
  	}
+ 
  	if( !lcd5only ) {
  
  		/* 検査用のネットワーク設定に変更する */
***************
*** 110,126 ****
  		fprintf(fd, "auto lo wlan0 eth0\n");
  		fprintf(fd, "iface lo inet loopback\n");
  		fprintf(fd, "iface eth0 inet static\n");
! 		fprintf(fd, "  address 192.168.0.110\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.0.0\n");
! 		fprintf(fd, "  broadcast 192.168.0.255\n");
! 		fprintf(fd, "  gateway 192.168.0.200\n");
  		fprintf(fd, "iface wlan0 inet static\n");
! 		fprintf(fd, "  address 192.168.0.111\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.0.0\n");
! 		fprintf(fd, "  broadcast 192.168.0.255\n");
! 		fprintf(fd, "  gateway 192.168.0.200\n");
  		fclose(fd);
  
  		printf("######################################################\n");
--- 132,148 ----
  		fprintf(fd, "auto lo wlan0 eth0\n");
  		fprintf(fd, "iface lo inet loopback\n");
  		fprintf(fd, "iface eth0 inet static\n");
! 		fprintf(fd, "  address "CLIENT_ETH0_IP_ADDR"\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.2.0\n");
! 		fprintf(fd, "  broadcast 192.168.2.255\n");
! 		fprintf(fd, "  gateway "SERVER_ETH0_IP_ADDR"\n");
  		fprintf(fd, "iface wlan0 inet static\n");
! 		fprintf(fd, "  address "CLIENT_WLAN0_IP_ADDR"\n");
  		fprintf(fd, "  netmask 255.255.255.0\n");
! 		fprintf(fd, "  network 192.168.3.0\n");
! 		fprintf(fd, "  broadcast 192.168.3.255\n");
! 		fprintf(fd, "  gateway "SERVER_WLAN0_IP_ADDR"\n");
  		fclose(fd);
  
  		printf("######################################################\n");
***************
*** 130,150 ****
  			printf("有線LANのMACアドレス書き込みを途中で終了しました！！!\n");
  			exit(1);
  		}
  		printf("######################################################\n");
  		printf("有線LAN(eth0)を検査します\n");
  		printf("有線LANコネクタと検査用ルータが接続されている必要があります\n");
  		printf("######################################################\n");
  		if( eth0_kensa() ) {
- 			printf("有線LAN(eth0)の検査を途中で終了しました！！!\n");
- 			exit(1);
  		}
  		printf("######################################################\n");
  		printf("無線LAN(wlan0), SDIOを検査します\n");
  		printf("CM-J100が接続されている必要があります\n");
  		printf("######################################################\n");
  		if( wlan0_kensa() ) {
- 			printf("無線LAN(wlan0), SDIOの検査を途中で終了しました！！!\n");
- 			exit(1);
  		}
  
  		printf("######################################################\n");
--- 152,170 ----
  			printf("有線LANのMACアドレス書き込みを途中で終了しました！！!\n");
  			exit(1);
  		}
+ 
  		printf("######################################################\n");
  		printf("有線LAN(eth0)を検査します\n");
  		printf("有線LANコネクタと検査用ルータが接続されている必要があります\n");
  		printf("######################################################\n");
  		if( eth0_kensa() ) {
  		}
+ 		
  		printf("######################################################\n");
  		printf("無線LAN(wlan0), SDIOを検査します\n");
  		printf("CM-J100が接続されている必要があります\n");
  		printf("######################################################\n");
  		if( wlan0_kensa() ) {
  		}
  
  		printf("######################################################\n");
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/kensa.h buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/kensa.h
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/kensa.h	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/kensa.h	2015-10-19 17:29:35.859322900 +0900
***************
*** 0 ****
--- 1,33 ----
+ /*
+  * kensa.h
+  *
+  * CKB Kensa program
+  *
+  * Copyright 2012 Computex Co.,Ltd.
+  *
+  */
+ 
+ #ifndef _KENSA_H_
+ #define _KENSA_H_
+ 
+ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
+ 
+ #define SERVER_ETH0_IP_ADDR  "192.168.2.100"
+ #define CLIENT_ETH0_IP_ADDR  "192.168.2.200"
+ 
+ #define SERVER_WLAN0_IP_ADDR	"192.168.3.100"
+ #define CLIENT_WLAN0_IP_ADDR	"192.168.3.200"
+ 
+ #define AP_SSID			"CKBKENSA3"
+ #define AP_PASSWORD		"Computex3"
+ 
+ #define IPERF_LOG_FILE			"/tmp/iperf.log"
+ #define IPERF_TASK_FILE			"/tmp/iperf.task"
+ #define IPERF_SEND_MIN_SPEED	15000
+ #define IPERF_RECV_MIN_SPEED	13000
+ 
+ #define IPERF_WLAN_SEND_MIN_SPEED	2000
+ #define IPERF_WLAN_RECV_MIN_SPEED	1000
+ 
+ #define ETHLINK_TO				60		/* secs */
+ #endif
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/kensa-server.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/kensa-server.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/kensa-server.c	1970-01-01 09:00:00.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/kensa-server.c	2015-10-19 09:58:53.039469600 +0900
***************
*** 0 ****
--- 1,190 ----
+ /*
+  * kensa.c
+  *
+  * CKB-3352 Kensa server program
+  *
+  * Copyright 2013 Computex Co.,Ltd.
+  *
+  */
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <signal.h>
+ #include <sys/fcntl.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include "kensa.h"
+ #include <termios.h>
+ 
+ struct termios orig_tio, new_tio;
+ void saveOrigTTYsettings()
+ {
+ 	 tcgetattr(0, &orig_tio);
+ }
+ void restoreOrigTTYsettings()
+ {
+ 	 tcsetattr(0, TCSANOW, &orig_tio);
+ }
+ 
+ _Bool kbhit(u_char *ch)
+ {
+     return read(0,ch,1)?1:0;
+ }
+ 
+ void setKbhitMode()
+ {
+ 	memcpy(&new_tio, &orig_tio, sizeof(struct termios));
+ 	new_tio.c_cc[VMIN]=0;
+     new_tio.c_lflag &= ~ICANON;
+     new_tio.c_lflag &= ~ECHO;
+     new_tio.c_lflag &= ~ISIG;
+ //    new_tio.c_cc[VMIN] = 1;
+     new_tio.c_cc[VTIME] = 0;
+     tcsetattr(0, TCSANOW, &new_tio);
+ }
+ 
+ int kensa_yes_no(const char *message)
+ {
+ 	char ch;
+ 	printf(message);
+ 	while(1){
+ 		scanf(" %c", &ch);
+ 		getchar();		/* lose the Enter key */
+ 		switch(ch)
+ 		{
+ 		case 'N':
+ 		case 'n':
+ 			return 1;
+ 		case 'Y':
+ 		case 'y':
+ 			return 0;
+ 		default:
+ 			printf("無効な入力、再試行してください。。。\n");
+ 		}
+ 	}
+ }
+ 
+ 
+ static void sig(int sig)
+ {
+ 	fflush(stderr);
+ 	printf("signal %d caught\n", sig);
+ 	fflush(stdout);
+ 	exit(1);
+ }
+ 
+ void help()
+ {
+ 	printf("Usage: kensa-server\n");
+ }
+ 
+ /* main() */
+ int main(int argc, char* argv[])
+ {
+ 	int lcd5only = 0;	// 1=LCDボードの検査を行う
+ 	int flag;
+ 	FILE *fd;
+ 	char *argv_cmd[10];
+ 	int rev;			// 0=Rev.A以前、1=Rev.B以降
+ 	struct stat st;
+ 	int filesize;
+ 	char *buf;
+ 	int bufsize = 0;
+ 	u_char ch;
+ #if 0
+ 	/* signal handler */
+ 	signal(SIGSEGV, sig);
+ 	signal(SIGINT, sig);
+ 	signal(SIGTERM, sig);
+ #endif
+ 	system("killall vpif_cam_app");
+ 	system("killall httpd");
+ 	system("killall udhcpc");
+ 	system("killall avahi-daemon");
+ 	system("killall wpa_supplicant");
+ 	system("killall hostapd");
+ 	
+ 	printf("**** Kensa server application\nTerminating any running iperf...");
+ 	system("killall iperf");
+ 	sleep(2);
+ 	/* 検査用のネットワーク設定に変更する */
+ 	system("ifdown eth0");
+ 	system("ifconfig eth0 down");
+ 	system("ifdown wlan0");
+ 
+ 	fd=fopen("/etc/network/interfaces","w");
+ 	fprintf(fd, "auto lo wlan0 eth0\n");
+ 	fprintf(fd, "iface lo inet loopback\n");
+ 	fprintf(fd, "iface eth0 inet static\n");
+ 	fprintf(fd, "  address "SERVER_ETH0_IP_ADDR"\n");
+ 	fprintf(fd, "  netmask 255.255.255.0\n");
+ 	fprintf(fd, "  network 192.168.2.0\n");
+ 	fprintf(fd, "  broadcast 192.168.2.255\n");
+ 	fprintf(fd, "  gateway "SERVER_ETH0_IP_ADDR"\n");
+ 	fprintf(fd, "iface wlan0 inet static\n");
+ 	fprintf(fd, "  address "SERVER_WLAN0_IP_ADDR"\n");
+ 	fprintf(fd, "  netmask 255.255.255.0\n");
+ 	fprintf(fd, "  network 192.168.3.0\n");
+ 	fprintf(fd, "  broadcast 192.168.3.255\n");
+ 	fprintf(fd, "  gateway "SERVER_WLAN0_IP_ADDR"\n");
+ 	fclose(fd);
+ 
+ 	system("ifup eth0");
+ 	system("ifconfig eth0 "SERVER_ETH0_IP_ADDR" up");
+ 	system ("/etc/network/wlan-scripts/HOSTAPD_WPA2.sh n 1 '"AP_SSID"' '"AP_PASSWORD"'");
+ 
+ 	saveOrigTTYsettings();
+ 	setKbhitMode();
+ 	printf("**** Press q to terminate application ****\n");
+ 	while(1)
+ 	{
+ 		if(kbhit(&ch)==1)
+ 		{
+ 			if(ch=='q')
+ 				break;
+ 		}
+ 		system("ps -a | grep \"iperf -s\" | awk '{print $3}' > " IPERF_TASK_FILE);
+ 		system("sync");
+ 		sleep(1);
+ 		/* get the file length */
+ 		stat(IPERF_TASK_FILE, &st);
+ 		filesize = st.st_size;
+ 		if(filesize == 0)
+ 		{
+ 			goto _iperf;
+ 		}
+ 		fd = open(IPERF_TASK_FILE, O_RDONLY);
+ 		if( fd < 0 )
+ 		{
+ 			printf("Error opening "IPERF_TASK_FILE"\n");
+ 			continue;
+ 		}
+ 		if(filesize > bufsize)
+ 		{
+ 			if(bufsize)
+ 				free(buf);
+ 			buf = malloc(filesize);
+ 			bufsize = filesize;
+ 		}
+ 		/* read the file in one go */
+ 		if(read(fd, buf, filesize) != filesize)
+ 		{
+ 			printf("Error reading "IPERF_TASK_FILE"\n");
+ 			close(fd);
+ 			continue;
+ 		}
+ 		close(fd);
+ 		if(!strncmp("iperf", buf, 5))
+ 			continue;
+ _iperf:
+ 		printf("Starting iperf...\n");
+ 		system("iperf -s &");
+ 		printf("iperf started\n");
+ 		sleep(1);
+ 	}
+ 	if(bufsize)
+ 		free(buf);
+ 
+ 	restoreOrigTTYsettings();
+ 	return 0;
+ }
+ 
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/macwrite.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/macwrite.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/macwrite.c	2014-01-21 17:14:22.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/macwrite.c	2015-10-14 10:05:31.028151900 +0900
***************
*** 53,58 ****
--- 53,61 ----
  	printf("有線LANのMACアドレスを設定します。\n");
  	if( buf2[0] == 0x5a ) {
  		printf("現在の設定は %02X:%02X:%02X:%02X:%02X:%02X に設定されています\n", buf2[1], buf2[2], buf2[3], buf2[4], buf2[5], buf2[6]);
+ 		if( 0 != kensa_yes_no("変更しますか？(Y/N)") ) {
+ 			return 0;
+ 		}
  	} else {
  		printf("現在、MACアドレスが設定されていません\n");
  	}
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/Makefile buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/Makefile
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/Makefile	2014-05-22 13:48:54.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/Makefile	2015-10-15 11:38:17.471867300 +0900
***************
*** 11,17 ****
  APP= kensa
  LIB= -ldl -lpthread
  
! SRCS= kensa.c led_kensa.c vpif_lcd.c macwrite.c eth0.c wlan0.c ts_kensa.c storage.c
  
  all: $(SRCS)
  ifndef KERNEL_HEADERS
--- 11,18 ----
  APP= kensa
  LIB= -ldl -lpthread
  
! SRCS= kensa.c led_kensa.c vpif_lcd.c macwrite.c eth0.c wlan0.c ts_kensa.c storage.c bd_rev.c
! SERVER_SRCS= kensa-server.c
  
  all: $(SRCS)
  ifndef KERNEL_HEADERS
***************
*** 19,26 ****
  	@echo "\"KERNEL_HEADERS\" should point to the Kernel headers directory. Try \"make KERNEL_HEADERS=<kernel header directory>\""
  else
  	$(CC) -o $(APP) $(SRCS) $(LIB)
  endif
  
  clean:
  	rm -f *.o $(APP)
! 
--- 20,28 ----
  	@echo "\"KERNEL_HEADERS\" should point to the Kernel headers directory. Try \"make KERNEL_HEADERS=<kernel header directory>\""
  else
  	$(CC) -o $(APP) $(SRCS) $(LIB)
+ 	$(CC) -o kensa-server $(SERVER_SRCS) $(LIB)
  endif
  
  clean:
  	rm -f *.o $(APP)
! 	rm -f kensa-server
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/wlan0.c buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/wlan0.c
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/ckb-rz/samples/kensa/wlan0.c	2014-02-10 11:50:39.000000000 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/ckb-rz/samples/kensa/wlan0.c	2015-10-20 09:35:53.276297000 +0900
***************
*** 11,18 ****
--- 11,20 ----
  #include <stdlib.h>
  #include <string.h>
  #include <sys/fcntl.h>
+ #include "kensa.h"
  
  //#define _DEBUG
+ #define WLAN_RETRY_CNT	120				/* 2 mins approx */
  
  /* アクセスポイントに接続してネットワークにpingして無線LAN(wlan0)を検査する */
  int wlan0_kensa()
***************
*** 24,37 ****
  	int flag;
  	char *argv_cmd[10];
  	FILE* fp;
! 
  	/* wlan0をアクセスポイント(CMJKENSA11)に接続する */
  	argv_cmd[0] = "/etc/network/wlan-scripts/INFR_WPA2.sh";	// WPA2-PSK(AES)
! 	argv_cmd[1] = "\"CMJKENSA11\"";				// SSID
! 	argv_cmd[2] = "\"Computex0332532901com\"";		// Passphrase
  	argv_cmd[3] = NULL;
  	ShellExecute(argv_cmd[0], argv_cmd);
  
  	/* wlan0をスタティックIPで接続する */
  	argv_cmd[0] = "/sbin/ifup";
  	argv_cmd[1] = "wlan0";
--- 26,47 ----
  	int flag;
  	char *argv_cmd[10];
  	FILE* fp;
! 	int ret;
! 	int retry;
! 	system("/etc/network/wlan-scripts/disconnect_wlan0.sh");
! 	sleep(2);
! 
! _begin:
! 	printf("無線LAN(wlan0)を検査します\n");
! 	ret = 0;
  	/* wlan0をアクセスポイント(CMJKENSA11)に接続する */
  	argv_cmd[0] = "/etc/network/wlan-scripts/INFR_WPA2.sh";	// WPA2-PSK(AES)
! 	argv_cmd[1] = "\""AP_SSID"\"";				// SSID
! 	argv_cmd[2] = "\""AP_PASSWORD"\"";		// Passphrase
  	argv_cmd[3] = NULL;
  	ShellExecute(argv_cmd[0], argv_cmd);
  
+ #if 0
  	/* wlan0をスタティックIPで接続する */
  	argv_cmd[0] = "/sbin/ifup";
  	argv_cmd[1] = "wlan0";
***************
*** 41,49 ****
  		printf("ifup wlan0 に失敗しました。\n");
  		return(1);
  	}
  
  	/* wlan0をが有効になるのを待つ */
! 	printf("wireless AP(CMJKENSA11) ");	fflush(stdout);
  	for( ; ; ) {
  		fp=fopen("/sys/class/net/wlan0/operstate","r");
  #if defined(_DEBUG)
--- 51,81 ----
  		printf("ifup wlan0 に失敗しました。\n");
  		return(1);
  	}
+ #else
+ 	//system("ifup wlan0");
+ 	sleep(3);
+ #endif
+ 	printf("Waiting for wlan0 to connect to AP("AP_SSID")...\n");
+ 	/* wait until wlan0 gets connected */
+ 	retry = 0;
+ 	while(retry < WLAN_RETRY_CNT) {
+ 		if(!system("iwconfig wlan0 | grep "AP_SSID))
+ 		{
+ 			break;
+ 		}
+ 		printf(".");	fflush(stdout);
+ 		retry++;
+ 		sleep(1);
+ 	}
+ 
+ 	if(retry == WLAN_RETRY_CNT) {
+ 		printf("wlan0 couldn't connect to AP\n");
+ 		ret = 1;
+ 		goto _out;
+ 	}
  
  	/* wlan0をが有効になるのを待つ */
! 	printf("wireless AP("AP_SSID") ");	fflush(stdout);
  	for( ; ; ) {
  		fp=fopen("/sys/class/net/wlan0/operstate","r");
  #if defined(_DEBUG)
***************
*** 61,90 ****
  				break;
  			}
  		}
- 		sleep(1);
  		printf(".");	fflush(stdout);
  	}
  	printf("connect.\n");
  
  	/* routeが確認できるまで待つ */
  	system("route");
! 
  	/* wlan0でpingする */
  	argv_cmd[0] = "/bin/ping";
  	argv_cmd[1] = "-I";
  	argv_cmd[2] = "wlan0";
  	argv_cmd[3] = "-c";
  	argv_cmd[4] = "10";
! 	argv_cmd[5] = "192.168.0.200";	/* AP(KENSA11) IP address */
  	argv_cmd[6] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ping -I wlan0 -c 10 192.168.0.200 に失敗しました。\n");
! 		return(1);
  	}
! 	system("ifdown wlan0");
! 
! 
! 	return 0;
  }
  
--- 93,135 ----
  				break;
  			}
  		}
  		printf(".");	fflush(stdout);
+ 		sleep(1);
  	}
  	printf("connect.\n");
  
  	/* routeが確認できるまで待つ */
  	system("route");
! 	sleep(2);
! #if 0
  	/* wlan0でpingする */
  	argv_cmd[0] = "/bin/ping";
  	argv_cmd[1] = "-I";
  	argv_cmd[2] = "wlan0";
  	argv_cmd[3] = "-c";
  	argv_cmd[4] = "10";
! 	argv_cmd[5] = SERVER_WLAN0_IP_ADDR;	/* AP IP address */
  	argv_cmd[6] = NULL;
  	flag = ShellExecute(argv_cmd[0], argv_cmd);
  	if( flag != 0 ) {
  		printf("ping -I wlan0 -c 10 192.168.0.200 に失敗しました。\n");
! 		ret = 1;
! 		goto _out;
  	}
! #else
! 	ret = iperf_test("wlan0", SERVER_WLAN0_IP_ADDR, CLIENT_WLAN0_IP_ADDR, IPERF_WLAN_SEND_MIN_SPEED, IPERF_WLAN_RECV_MIN_SPEED);
! #endif
! _out:
! 	//system("ifdown wlan0"); // dono use this - leads to Segmentatio nfault in kernel sometimes
! 	system("/etc/network/wlan-scripts/disconnect_wlan0.sh");
! 	sleep(2);
! 	if(ret) {
! 		if( !kensa_yes_no("\nRetry test? [Y/N] : ")) {
! 			goto _begin;
! 		}
! 		on_error(ret, "無線LAN(wlan0), SDIOの検査を途中で終了しました！！!\n");
! 	}
! 	
! 	return ret;
  }
  
diff -crN buildroot-2013.08.1-ckb-20150123-1/board/ckb/Makefile.in buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/Makefile.in
*** buildroot-2013.08.1-ckb-20150123-1/board/ckb/Makefile.in	2015-10-20 10:56:45.222171615 +0900
--- buildroot-2013.08.1-ckb-20150123-1-new/board/ckb/Makefile.in	2015-10-20 10:58:02.798170929 +0900
***************
*** 192,197 ****
--- 192,200 ----
  		APP_DEBUG=$(APP_DEBUG) \
  		-C $(BOARD_DIR)/samples/kensa
  	cp $(BOARD_DIR)/samples/kensa/kensa $(TARGET_DIR)/bin/
+ 	if [ -e "$(BOARD_DIR)/samples/kensa/kensa-server" ]; then \
+ 		cp $(BOARD_DIR)/samples/kensa/kensa-server $(TARGET_DIR)/bin/; \
+ 	fi
  	
  kensa_app-clean:
  	make clean -C $(BOARD_DIR)/samples/kensa
