migrate rsa git from private git (emuld) 2.0alpha master 2.0_alpha submit/master/20120920.151158
authorjihye kim <jihye1128.kim@samsung.com>
Wed, 22 Aug 2012 11:45:29 +0000 (20:45 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Wed, 22 Aug 2012 11:45:29 +0000 (20:45 +0900)
debian/changelog
debian/control
debian/emuld.postinst.in
include/emuld.h
packaging/emuld.spec
src/emuld.c

index d3815aa..572b8ea 100644 (file)
-emuld (0.2.5) unstable; urgency=low
+emuld (0.2.17) unstable; urgency=low
 
-  * fixed unexpected stop when memcpy size -1
+  * modified for scm build
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.17
 
- -- Sungmin Ha <sungmin82.ha@samsung.com>  Mon, 23 Apr 2012 12:16:52 +0900
+ -- Sungmin ha <sungmin82.ha@samsung.com> Thu, 09 Aug 2012 21:00:18 +0900
 
-emuld (0.2.4) unstable; urgency=low
+emuld (0.2.15) unstable; urgency=low
 
-  * modified post install script for fix install error
+  * Permission of sdcard partition changed from 755 to 777.
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.15
 
- -- Sungmin Ha <sungmin82.ha@samsung.com>  Mon, 20 Feb 2012 15:16:52 +0900
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Wed, 11 Jul 2012 19:38:44 +0900
 
-emuld (0.2.3) unstable; urgency=low
+emuld (0.2.14) unstable; urgency=low
 
-  * modified for build only i386
+  * modified for checking resource busy when umount sdcard
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.14
 
- -- Sungmin Ha <sungmin82.ha@samsung.com>  Sat, 18 Feb 2012 13:06:52 +0900
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Thu, 05 Jul 2012 21:03:00 +0900
 
-emuld (0.2.2) unstable; urgency=low
+emuld (0.2.12) unstable; urgency=low
+
+  * modified for checking return value of fopen
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.12
+
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Fri, 22 Jun 2012 18:23:00 +0900
+
+emuld (0.2.10) unstable; urgency=low
+
+  * deleted process kill when umount
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.10
+
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Thu, 15 Jun 2012 16:16:00 +0900
+
+emuld (0.2.9) unstable; urgency=low
+
+  * modified vconf key path for sdcard supporting
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.9
+
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Thu, 14 Jun 2012 16:04:00 +0900
+
+emuld (0.2.8) unstable; urgency=low
+
+  * added sdcard mount/umount handling
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.8
+
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Tue, 29 May 2012 18:47:00 +0900
+
+emuld (0.2.7) unstable; urgency=low
+
+  * added exception handling
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.7
+
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Mon, 14 May 2012 18:10:00 +0900
+
+emuld (0.2.6) unstable; urgency=low
+
+  * modified how to get host ip
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.6
+
+ -- Sungmin ha <sungmin82.ha@samsung.com>  Fri, 11 May 2012 18:05:00 +0900
+
+emuld (0.2.5) unstable; urgency=low
+
+  * add setting location replay and modify nfc.
+  * need sinchronization with event injector
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.5
+
+ -- Jihye kim <jihye1128.kim@samsung.com>  Thu, 10 May 2012 11:30:00 +0900
+
+emuld (0.2.4) unstable; urgency=low
+
+  * back to the 0.2.2
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.4
+
+ -- Jihye kim <jihye1128.kim@samsung.com>  Thu, 4 May 2012 11:50:00 +0900
+
+emuld (0.2.3) unstable; urgency=low
 
-  * modified for distinction close fd by event injector
+  * Add making 'sdkMsg' file during post install.
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.3
 
- -- Sungmin Ha <sungmin82.ha@samsung.com>  Wed, 15 Feb 2012 15:35:52 +0900
+ -- Jihye kim <jihye1128.kim@samsung.com>  Wen, 02 May 2012 14:00:00 +0900
 
 emuld (0.2.2) unstable; urgency=low
 
-  * modified for distinction close fd by event injector
+  * Update changelog version.
+  * Git: slp/pkgs/e/emulator-daemon
+  * Tag: emuld_0.2.2
 
- -- Sungmin Ha <sungmin82.ha@samsung.com>  Wed, 15 Feb 2012 15:35:52 +0900
+ -- Kitae kim <kt920.kim@samsung.com>  Thu, 27 Mar 2012 20:00:00 +0900
 
 emuld (0.2.1) unstable; urgency=low
 
index f177ceb..15fa734 100644 (file)
@@ -1,8 +1,8 @@
 Source: emuld
 Section: misc
 Priority: extra
-Maintainer: Sungmin Ha <sungmin82.ha@samsung.com>
-Standards-Version: 0.2.5
+Maintainer:Sungmin Ha <sungmin82.ha@samsung.com>,Jihye Kim <jihye1128.kim@samsung.com>,Yeongkyoon Lee <yeongkyoon.lee@samsung.com>
+Standards-Version: 0.2.17
 
 Package: emuld
 Section: misc
index 2abc24c..18091d3 100644 (file)
@@ -1,3 +1,2 @@
 #!/bin/sh
 chmod 777 /usr/bin/emuld
-       
index 764bd03..5c528eb 100644 (file)
 #include <stdarg.h>
 #include <sys/time.h>
 #include <pthread.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <errno.h>
+#include <sys/mount.h>
 
 /* definition */
 #define MAX_CLIENT             10000
@@ -48,7 +53,7 @@
 #define VMODEM_PORT            3578
 #define GPSD_PORT              3579
 #define SENSORD_PORT           3580
-#define EMUL_IP                        "10.0.2.16"
+#define SRV_IP                         "10.0.2.2"
 #define ID_SIZE                        10
 #define HEADER_SIZE            4
 #define EMD_DEBUG
@@ -68,10 +73,13 @@ int recv_data(int event_fd, char** r_databuf, int size);
 void client_recv(int event_fd);
 void server_process(void);
 void end_server(int sig);
+int is_mounted(void);
 
 static int log_print = -1;
 FILE* log_fd;
 
+// location
+void setting_location(char* databuf);
 #define LOG(fmt, arg...) \
        do { \
                log_print_out("[%s:%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); \
index 16a56de..ed9d37e 100644 (file)
@@ -1,6 +1,6 @@
 #git:/slp/pkgs/e/emulator-daemon
 Name: emuld
-Version: 0.2.5
+Version: 0.2.17
 Release: 1
 Summary: emuld is used for communication emulator between and ide.
 License: Apache
@@ -35,6 +35,8 @@ rm -rf install_manifes.txt
 
 %post
 chmod 777 /usr/bin/emuld
+mkdir -p /opt/nfc
+touch /opt/nfc/sdkMsg
 
 %postun
 
index 297d6bd..dc386d7 100644 (file)
@@ -47,6 +47,7 @@ int g_svr_port;                       /* global server port number */
 int g_vm_sockfd;               /* vmodem fd */
 int g_sdbd_sockfd = -1;                /* sdbd fd */
 static int g_vm_connect_status;        /* connection status between emuld and vmodem  */
+int g_sdcard_sockfd = -1;
 
 pthread_t tid[MAX_CLIENT + 1];
 
@@ -65,6 +66,25 @@ int g_epoll_fd;                              /* epoll fd */
 
 struct epoll_event g_events[MAX_EVENTS]; 
 
+// for vmodem packets
+typedef struct // lxt_message
+{
+       unsigned short length;
+       unsigned char group;
+       unsigned char action;
+       void *data; 
+} LXT_MESSAGE;
+
+void TAPIMessageInit(LXT_MESSAGE *packet)
+{       
+       packet->length = 0;
+       packet->group = 0;
+       packet->action = 0;
+       packet->data = 0;
+}
+
+char SDpath[256];
+       
 /*--------------------------------------------------------------*/
 /* FUNCTION PART 
    ---------------------------------------------------------------*/
@@ -174,6 +194,158 @@ void* init_vm_connect(void* data)
        
        g_vm_connect_status = 1;
        pthread_exit((void *) 0); 
+}
+
+int is_mounted()
+{
+       int ret = -1, i = 0;
+       struct stat buf;
+       char file_name[128];
+       memset(file_name, '\0', sizeof(file_name));
+
+       for(i = 0; i < 10; i++)
+       {
+               sprintf(file_name, "/dev/mmcblk%d", i);
+               ret = access( file_name, F_OK );
+               if( ret == 0 )
+               {
+                       lstat(file_name, &buf);
+                       if(S_ISBLK(buf.st_mode))
+                               return 1;
+                       else
+                               return 0;
+               }
+       }
+
+       return 0;
+}
+
+void* mount_sdcard(void* data)
+{
+       int ret = -1, i = 0, vconf_value = -1;  
+       struct stat buf;
+       char file_name[128], command[256];
+       memset(file_name, '\0', sizeof(file_name));
+       memset(command, '\0', sizeof(command));
+
+       LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+
+       LOG("start sdcard mount thread");
+
+       pthread_detach(pthread_self());
+
+       while(ret < 0)
+       {       
+               for(i = 0; i < 10; i++)
+               {
+                       sprintf(file_name, "/dev/mmcblk%d", i);
+                       ret = access( file_name, F_OK );
+                       if( ret == 0 )
+                       {
+                               lstat(file_name, &buf);
+                               if(!S_ISBLK(buf.st_mode))
+                               {
+                                       sprintf(command, "rm -rf %s", file_name);
+                                       system(command);
+                               }
+                               else
+                                       break;
+                       }
+               }
+
+               if( i != 10 )
+               {
+                       LOG( "%s is exist", file_name);
+                       ret = mount(file_name, "/mnt/mmc", "ext3", 0, "");
+                       LOG("mount ret = %d, errno = %d", ret, errno);
+                       
+                       LOG("sdcard fd: %d", g_sdcard_sockfd);
+                       if(g_sdcard_sockfd != -1)
+                       {
+                               packet->length = strlen(SDpath);                // length
+                               packet->group = 11;                             // sdcard
+                               if(ret == 0)
+                                       packet->action = 1;     // mounted
+                               else
+                                       packet->action = 5;     // failed
+
+                               send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+                               LOG("SDpath is %s", SDpath);
+                               send(g_sdcard_sockfd, SDpath, packet->length, 0);
+                               
+                               if(ret == 0)
+                               {
+                                       system("chmod -R 777 /opt/storage/sdcard");
+                                       system("vconftool set -t int memory/sysman/mmc 1 -i -f");
+                               }
+                       }
+
+                       break;
+               }
+               else
+               {
+                       LOG( "%s is not exist", file_name);
+                       sleep(1);       
+               }               
+       }
+
+       pthread_exit((void *) 0); 
+} 
+
+int umount_sdcard(void)
+{
+       int ret = -1, i = 0;    
+       char file_name[128];
+       memset(file_name, '\0', sizeof(file_name));
+       LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+       memset(packet, 0, sizeof(LXT_MESSAGE));
+
+       LOG("start sdcard umount");
+
+       pthread_cancel(tid[1]);
+
+       for(i = 0; i < 10; i++)
+       {
+               sprintf(file_name, "/dev/mmcblk%d", i);
+               ret = access( file_name, F_OK);
+               if ( ret == 0 )
+               {
+                       LOG( "%s is exist", file_name);
+                       ret = umount("/mnt/mmc");
+                       LOG("umount ret = %d, errno = %d", ret, errno);
+                       
+                       LOG("sdcard fd: %d", g_sdcard_sockfd);
+                       if(g_sdcard_sockfd != -1)
+                       {
+                               packet->length = strlen(SDpath);                // length
+                               packet->group = 11;                             // sdcard
+                               if(ret == 0)
+                                       packet->action = 0;                             // unmounted
+                               else
+                                       packet->action = 4;                             // failed
+
+                               send(g_sdcard_sockfd, (void*)packet, sizeof(char) * HEADER_SIZE, 0);
+                               LOG("SDpath is %s", SDpath);
+                               send(g_sdcard_sockfd, SDpath, packet->length, 0);
+                               
+                               if(ret == 0)
+                               {
+                                       memset(SDpath, '\0', sizeof(SDpath));
+                                       sprintf(SDpath, "umounted");
+                                       system("vconftool set -t int memory/sysman/mmc 0 -i -f");
+                               }                               
+                       }
+
+                       break;
+               }
+               else
+               {
+                       LOG( "%s is not exist", file_name);
+               }
+       }
+
+       return ret;
 } 
 
 void epoll_init(void)
@@ -247,7 +419,7 @@ void userpool_delete(int cli_fd)
        {
                if(g_client[i].cli_sockfd == cli_fd)
                {
-                       g_client[i].cli_sockfd = -1;
+                       g_client[i].cli_sockfd = -1;    
                        break;
                }
        }
@@ -275,6 +447,12 @@ int parse_val(char *buff, unsigned char data, char *parsbuf)
 void udp_init(void)
 {
        LOG("start");
+       char* emul_ip = getenv("HOSTNAME");
+       if(emul_ip == NULL)
+       {
+               LOG("emul_ip is null");
+               assert(0);
+       }
 
        if ((uSensordFd=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1){
                fprintf(stderr, "socket error!\n");
@@ -283,7 +461,7 @@ void udp_init(void)
        memset((char *) &si_sensord_other, 0, sizeof(si_sensord_other));
        si_sensord_other.sin_family = AF_INET;
        si_sensord_other.sin_port = htons(sensord_port);
-       if (inet_aton(EMUL_IP, &si_sensord_other.sin_addr)==0) {
+       if (inet_aton(emul_ip, &si_sensord_other.sin_addr)==0) {
                fprintf(stderr, "inet_aton() failed\n");
        }
 
@@ -294,56 +472,32 @@ void udp_init(void)
        memset((char *) &si_gpsd_other, 0, sizeof(si_gpsd_other));
        si_gpsd_other.sin_family = AF_INET;
        si_gpsd_other.sin_port = htons(gpsd_port);
-       if (inet_aton(EMUL_IP, &si_gpsd_other.sin_addr)==0) {
+       if (inet_aton(emul_ip, &si_gpsd_other.sin_addr)==0) {
                fprintf(stderr, "inet_aton() failed\n");
        }
 }
 
-// for vmodem packets
-typedef struct // lxt_message
-{
-       unsigned short length;
-       unsigned char group;
-       unsigned char action;
-       void *data; 
-} LXT_MESSAGE;
-
-void TAPIMessageInit(LXT_MESSAGE *packet)
-{       
-       packet->length = 0;
-       packet->group = 0;
-       packet->action = 0;
-       packet->data = 0;
-}       
-
 int recv_data(int event_fd, char** r_databuf, int size)
 {
        int recvd_size = 0;
        int len = 0;
        int getcnt = 0;
        char* r_tmpbuf = NULL;
-       
-       LOG("malloc size:%d\n", size);
-       r_tmpbuf = (char*)malloc(sizeof(char) * size);
-       *r_databuf = (char*)malloc(sizeof(char) * size);
-       memset(*r_databuf, '\0', sizeof(char) * size);
-       LOG("malloc success");
+
+       r_tmpbuf = (char*)malloc(sizeof(char) * size + 1);
+       *r_databuf = (char*)malloc(sizeof(char) * size + 1);
+       memset(*r_databuf, '\0', sizeof(char) * size + 1);
 
        while(recvd_size < size)
        {
                memset(r_tmpbuf, '\0', sizeof(char) * size);
                len = recv(event_fd, r_tmpbuf, size - recvd_size, 0);
-               if(len < 0)
-                       len = 0;
-
                memcpy((*r_databuf) + recvd_size, r_tmpbuf, len);
                recvd_size += len;
                getcnt++;
                if(getcnt > MAX_GETCNT)
                        break;
        }
-       
-       LOG("recvd_size:%d\n", recvd_size);
        free(r_tmpbuf);
        r_tmpbuf = NULL;
 
@@ -358,7 +512,13 @@ int powerdown_by_force()
 
        /* Getting poweroff duration */
        buf = getenv("PWROFF_DUR");
-       if (buf != NULL && strlen(buf) < 1024)
+       if(buf == NULL)
+       {
+               LOG("PWROFF_DUR is null");
+               assert(0);
+       }
+       
+       if (strlen(buf) < 1024)
                poweroff_duration = atoi(buf);
        if (poweroff_duration < 0 || poweroff_duration > 60) 
                poweroff_duration = POWEROFF_DURATION;
@@ -388,7 +548,7 @@ void client_recv(int event_fd)
        LXT_MESSAGE* packet = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
        memset(packet, 0, sizeof(LXT_MESSAGE));
 
-       LOG("start event_fd:%d, vmfd:%d", event_fd, g_vm_sockfd);
+       LOG("start");
        /* there need to be more precise code here */ 
        /* for example , packet check(protocol needed) , real recv size check , etc. */
 
@@ -467,8 +627,9 @@ void client_recv(int event_fd)
                        LOG("close event_fd: %d", event_fd);
                        userpool_delete(event_fd);
                        close(event_fd); /* epoll set fd also deleted automatically by this call as a spec */
-                       if(event_fd == g_sdbd_sockfd)                   
+                       if(event_fd == g_sdbd_sockfd)
                                g_sdbd_sockfd = -1;
+
                        return;
                }
 
@@ -563,53 +724,55 @@ void client_recv(int event_fd)
                        LOG("Something may be added in the data end, but it does not matter.");
                        LOG("location data recv buffer: %s", r_databuf);
 
-                       if(sendto(uGpsdFd, r_databuf, packet->length, 0, (struct sockaddr*)&si_gpsd_other, sglen) == -1)
-                               LOG("sendto error!");
+                       setting_location(r_databuf);
                }
                else if(strncmp(tmpbuf, "nfc", 3) == 0)
                {
-                       recvd_size = recv_data(event_fd, &r_databuf, 5);
-
-                       LOG("nfc packet length r_databuf: %s", r_databuf);
-
-                       if( recvd_size <= 0 )
+                       recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
+                       if( recvd_size <= 0 )
                        {
                                free(r_databuf);
                                r_databuf = NULL;
                                return;
                        }
+                       /*
+                       LOG("nfc packet length r_databuf: %s", r_databuf);
 
                                memset(tmpbuf, '\0', sizeof(tmpbuf));
                        parse_len = parse_val(r_databuf, 0x0a, tmpbuf);
 
                        int length = atoi(tmpbuf);
-                       
+                       */
+
+                       //byte to int
+                       int length = ((r_databuf[0] & 0xff) << 24 | (r_databuf[1] & 0xff) << 16
+                                       | (r_databuf[2] & 0xff) << 8 | (r_databuf[3] & 0xff)) ;
                        LOG("nfc packet converted length: %d", length);
                        free(r_databuf);
                        r_databuf = NULL;
 
                        recvd_size = recv_data(event_fd, &r_databuf, length);
-                       
+                       /*
                        char* strbuf = NULL;
                        strbuf = (char*)malloc(length + 1);
                        memset(strbuf, '\0', length + 1);
                        memcpy(strbuf, r_databuf, length);
-
-                       LOG("nfc data recv buffer: %s", strbuf);
+                       */
+                       LOG("nfc data recv buffer: %s", r_databuf);
 
                        FILE* fd;
                        fd = fopen("/opt/nfc/sdkMsg", "w");
-                       if(fd < 0)
+                       if(!fd)
                        {
                                LOG("nfc file open fail!");
                                free(packet);
                                packet = NULL;
                                return;
                        }
-                       fprintf(fd, "%s", strbuf);
+                       fprintf(fd, "%s", r_databuf);
                        fclose(fd);
-                       free(strbuf);
-                       strbuf = NULL;
+                       //free(strbuf);
+                       //strbuf = NULL;
                }
                else if(strncmp(tmpbuf, "system", 6) == 0)
                {
@@ -634,6 +797,84 @@ void client_recv(int event_fd)
                        powerdown_by_force();
 
                }
+               else if(strncmp(tmpbuf, "sdcard", 6) == 0)
+               {
+                       g_sdcard_sockfd = event_fd;
+                       recvd_size = recv_data(event_fd, &r_databuf, HEADER_SIZE);
+                       memcpy((void*)packet, (void*)r_databuf, HEADER_SIZE);   
+
+                       LOG("sdcard packet_length: %d", packet->length);
+
+                       free(r_databuf);
+                       r_databuf = NULL;
+                       recvd_size = recv_data(event_fd, &r_databuf, packet->length);
+
+                       LOG("Something may be added in the data end, but it does not matter.");
+                       LOG("sdcard data recv buffer: %s", r_databuf);
+                       
+                       char token[] = "\n";
+                       char tmpdata[recvd_size];
+                       memcpy(tmpdata, r_databuf, recvd_size);
+
+                       char* ret = NULL;
+                       ret = strtok(tmpdata, token);
+                       LOG("%s", ret);
+                       int mount_param = atoi(ret);
+                       int mount_status = 0;
+
+                       switch(mount_param)
+                       {
+                       case 0:                                                 // umount
+                               mount_status = umount_sdcard();
+                               if(mount_status == 0)                           
+                                       send_guest_server(r_databuf);
+                               break;
+                       case 1:                                                 // mount
+                               memset(SDpath, '\0', sizeof(SDpath));
+                               ret = strtok(NULL, token);
+                               strcpy(SDpath, ret);
+                               LOG("sdcard path is %s", SDpath);
+
+                               send_guest_server(r_databuf);
+                               if(pthread_create(&tid[1], NULL, mount_sdcard, NULL) != 0)
+                                       LOG("pthread create fail!");
+                               break;
+                       case 2:                                                 // mount status
+                               mount_status = is_mounted();
+
+                               LXT_MESSAGE* mntData = (LXT_MESSAGE*)malloc(sizeof(LXT_MESSAGE));
+                               memset(mntData, 0, sizeof(LXT_MESSAGE));
+
+                               mntData->length = strlen(SDpath);       // length
+                               mntData->group = 11;                    // sdcard
+
+                               switch(mount_status)
+                               {
+                               case 0:
+                                       mntData->action = 2;                    // umounted status
+                                       send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
+                                       
+                                       LOG("SDpath is %s", SDpath);
+                                       send(g_sdcard_sockfd, SDpath, mntData->length, 0);
+                                       memset(SDpath, '\0', sizeof(SDpath));
+                                       sprintf(SDpath, "umounted");
+                                       break;
+                               case 1:
+                                       mntData->action = 3;                    // mounted status
+                                       send(g_sdcard_sockfd, (void*)mntData, sizeof(char) * HEADER_SIZE, 0);
+
+                                       LOG("SDpath is %s", SDpath);
+                                       send(g_sdcard_sockfd, SDpath, mntData->length, 0);
+                                       break;
+                               default:
+                                       break;
+                               }
+                               break;
+                       default:
+                               LOG("unknown data %s", ret);
+                               break;
+                       }       
+               }               
                else
                {
                        LOG("Unknown packet: %s", tmpbuf);
@@ -718,6 +959,110 @@ void end_server(int sig)
        exit(0);
 }
 
+// location event
+char command[512];
+char latitude[128];
+char longitude[128];
+void setting_location(char* databuf)
+{
+       char* s = strchr(databuf, ',');
+       memset(command, 0, 256);
+       if (s == NULL) { // SET MODE
+               int mode = atoi(databuf);
+               switch (mode) {
+               case 0: // STOP MODE
+                       sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
+                       break;
+               case 1: // NMEA MODE (LOG MODE)
+                       sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
+                       break;
+               case 2: // MANUAL MODE
+                       sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 2 -f");
+                       break;
+               default:
+                       LOG("error(%s) : stop replay mode", databuf);
+                       sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 0 -f");
+                       break;
+               }
+               LOG("Location Command : %s", command);
+               system(command);
+       } else {
+               *s = '\0';
+               int mode = atoi(databuf);
+               if(mode == 1) { // NMEA MODE (LOG MODE)
+                       sprintf(command, "vconftool set -t string db/location/replay/FileName \"%s\"", s+1);
+                       LOG("%s", command);
+                       system(command);
+                       memset(command, 0, 256);
+                       sprintf(command, "vconftool set -t int db/location/replay/ReplayMode 1 -f");
+                       LOG("%s", command);
+                       system(command);
+               } else if(mode == 2) {
+                       memset(latitude,  0, 128);
+                       memset(longitude, 0, 128);
+                       char* t = strchr(s+1, ',');
+                       *t = '\0';
+                       strcpy(latitude, s+1);
+                       strcpy(longitude, t+1);
+                       //strcpy(longitude, s+1);
+                       //strcpy(latitude, databuf);
+                       // Latitude
+                       sprintf(command, "vconftool set -t double db/location/replay/ManualLatitude %s -f", latitude);
+                       LOG("%s", command);
+                       system(command);
+
+                       // Longitude
+                       sprintf(command, "vconftool set -t double db/location/replay/ManualLongitude %s -f", longitude);
+                       LOG("%s", command);
+                       system(command);
+               }
+       }
+}
+
+//sdcard event
+void send_guest_server(char* databuf)
+{
+       char buf[32];
+       struct sockaddr_in si_other;
+       int s, slen=sizeof(si_other);
+       FILE* fd;
+       char fbuf[16];
+       int port;
+       fd = fopen("/opt/home/sdb_port.txt", "r");
+       LOG("sdb_port.txt fopen fd is %d", fd);
+       if(!fd)
+       {
+               LOG("fopen /opt/home/sdb_port.txt fail");
+               port = 3581;
+       }
+       else
+       {
+               fgets(fbuf, 16, fd);
+               fclose(fd);
+               port = atoi(fbuf) + 3;
+       }
+
+       if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
+                 LOG("socket error!");
+           
+       memset((char *) &si_other, 0, sizeof(si_other));
+       si_other.sin_family = AF_INET;
+       si_other.sin_port = htons(port);
+       if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
+                 fprintf(stderr, "inet_aton() failed\n");
+       }
+
+       memset(buf, '\0', sizeof(buf));
+       sprintf(buf, "4\n%s", databuf);
+       LOG("sendGuestServer msg: %s", buf);
+       if(sendto(s, buf, sizeof(buf), 0, (struct sockaddr*)&si_other, slen) == -1)
+       {     
+               LOG("sendto error!");
+       }
+       
+       close(s);
+}
+
 int main( int argc , char *argv[])
 {
        if(log_print == 1)