Coap over TCP support for Tizen
authorkoushik.girijala <g.koushik@samsung.com>
Tue, 6 Oct 2015 05:44:24 +0000 (11:14 +0530)
committerJon A. Cruz <jonc@osg.samsung.com>
Thu, 19 Nov 2015 21:21:46 +0000 (21:21 +0000)
Tizen platform can be supported for coap over TCP

Change-Id: I8731181e3eac716b39ec40350df24d9c7fd03f74
Signed-off-by: koushik.girijala <g.koushik@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3585
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/SConscript
resource/csdk/connectivity/build/SConscript
resource/csdk/connectivity/build/tizen/SConscript
resource/csdk/connectivity/build/tizen/gbsbuild.sh
resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec
resource/csdk/connectivity/build/tizen/scons/SConscript
resource/csdk/connectivity/lib/libcoap-4.1.1/SConscript
resource/csdk/connectivity/samples/tizen/casample.c
resource/csdk/connectivity/src/SConscript
resource/csdk/connectivity/src/tcp_adapter/SConscript

index 0e37d4b..5de9342 100644 (file)
@@ -60,7 +60,7 @@ else:
                env.AppendUnique(CPPDEFINES = ['NO_IP_ADAPTER'])
 
        if with_tcp == True:
-               if target_os in['linux']:
+               if target_os in ['linux', 'tizen']:
                        env.AppendUnique(CPPDEFINES = ['TCP_ADAPTER'])
                        print "CA Transport is TCP"
                else:
index 045faab..953f3f3 100644 (file)
@@ -60,12 +60,13 @@ help_vars = Variables()
 help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
 help_vars.Add(BoolVariable('LOGGING', 'Enable stack logging', False))
 help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
-help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP', 'TCP']))
+help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP']))
 help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
 help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
 help_vars.Add(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload))
 help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP')))
 help_vars.Add(EnumVariable('BUILD_SAMPLE', 'Build with sample', 'ON', allowed_values=('ON', 'OFF')))
+help_vars.Add(BoolVariable('WITH_TCP', 'Enable TCP', False))
 
 help_vars.AddVariables(('DEVICE_NAME', 'Network display name for device', 'OIC-DEVICE', None, None),)
 
index c8c105c..57a4e90 100644 (file)
@@ -12,12 +12,13 @@ buildsample = env.get('BUILD_SAMPLE')
 release_mode = env.get('RELEASE')
 secured = env.get('SECURED')
 logging = env.get('LOGGING')
+with_tcp = env.get('WITH_TCP')
 
 print "Given Transport is %s" % transport
 print "Given OS is %s" % target_os
 
 if target_os == 'tizen':
-       command = "sh resource/csdk/connectivity/build/tizen/gbsbuild.sh %s %s %s %s %s" % (transport, secured, buildsample, release_mode, logging)
+       command = "sh resource/csdk/connectivity/build/tizen/gbsbuild.sh %s %s %s %s %s %s" % (transport, secured, buildsample, release_mode, logging, with_tcp)
        print "Created Command is %s" % command
        gbs_script = env.Command('gbs_build', None, command)
        AlwaysBuild ('gbs_script')
\ No newline at end of file
index ac2ba58..6ab0e87 100755 (executable)
@@ -25,8 +25,12 @@ export RELEASE=$4
 echo $5
 export LOGGING=$5
 
+echo $6
+export WITH_TCP=$6
+
 echo $TARGET_TRANSPORT
 echo $BUILD_SAMPLE
+echo $WITH_TCP
 
 rm -rf $name-$version
 
@@ -90,7 +94,7 @@ if [ ! -d .git ]; then
 fi
 
 echo "Calling core gbs build command"
-gbscommand="gbs build -A armv7l --include-all  --repository ./ --define 'TARGET_TRANSPORT $1' --define 'SECURED $2' --define 'RELEASE $4' --define 'LOGGING $5'"
+gbscommand="gbs build -A armv7l --include-all  --repository ./ --define 'TARGET_TRANSPORT $1' --define 'SECURED $2' --define 'RELEASE $4' --define 'LOGGING $5' --define 'WITH_TCP $6'"
 echo $gbscommand
 if eval $gbscommand; then
    echo "Core build is successful"
index acb41b7..8c3a25b 100644 (file)
@@ -35,7 +35,7 @@ SLP oicca application
 echo %{ROOTDIR}
 
 scons TARGET_OS=tizen -c
-scons TARGET_OS=tizen TARGET_TRANSPORT=%{TARGET_TRANSPORT} SECURED=%{SECURED} RELEASE=%{RELEASE} LOGGING=%{LOGGING}
+scons TARGET_OS=tizen TARGET_TRANSPORT=%{TARGET_TRANSPORT} SECURED=%{SECURED} RELEASE=%{RELEASE} LOGGING=%{LOGGING} WITH_TCP=%{WITH_TCP}
 
 %install
 mkdir -p %{DEST_INC_DIR}
index 9a9644d..a06d5ee 100644 (file)
@@ -7,6 +7,7 @@ Import('env')
 
 target_os = env.get('TARGET_OS')
 transport = env.get('TARGET_TRANSPORT')
+with_tcp = env.get('WITH_TCP')
 
 print "Given Transport is %s" % transport
 
@@ -41,6 +42,12 @@ else:
        else:
                env.AppendUnique(CPPDEFINES = ['NO_WIFI_ADAPTER'])
 
+       if with_tcp == True:
+               env.AppendUnique(CPPDEFINES = ['TCP_ADAPTER'])
+               print "CA Transport is TCP"
+       else:
+               env.AppendUnique(CPPDEFINES = ['NO_TCP_ADAPTER'])
+
 
 env.SConscript(['../con/lib/libcoap-4.1.1/SConscript'])
 env.SConscript(['../con/SConscript'])
index ded6fd0..876bc03 100644 (file)
@@ -37,7 +37,7 @@ if target_os not in ['windows', 'winrt']:
        libcoap_env.AppendUnique(CFLAGS = ['-Wall', '-ffunction-sections',
                        '-fdata-sections', '-fno-exceptions'])
 
-if target_os == 'linux':
+if target_os in ['linux', 'tizen']:
        if with_tcp == True:
                libcoap_env.AppendUnique(CPPDEFINES = ['WITH_TCP'])
 
index 162b512..7e0810f 100644 (file)
@@ -59,6 +59,9 @@
 #define COAPS_PREFIX         "coaps://"
 #define COAPS_PREFIX_LEN     8
 
+#define COAP_TCP_PREFIX      "coap+tcp://"
+#define COAP_TCP_PREFIX_LEN  11
+
 // Iotivity Device Identity.
 const unsigned char IDENTITY[] = ("1111111111111111");
 
@@ -425,6 +428,7 @@ void send_request()
         printf("Enter the URI like below....\n");
         printf("coap://10.11.12.13:4545/resource_uri ( for IP )\n");
         printf("coap://10:11:12:13:45:45/resource_uri ( for BT )\n");
+        printf("coap+tcp://10:11:12:13:45:45/resource_uri ( for TCP )\n");
     }
     else
     {
@@ -808,6 +812,7 @@ void select_network()
     printf("IP     : 0\n");
     printf("GATT   : 1\n");
     printf("RFCOMM : 2\n");
+    printf("TCP    : 4\n");
     printf("select : ");
 
     char buf[MAX_BUF_LEN] = { 0 };
@@ -818,7 +823,7 @@ void select_network()
 
     int number = buf[0] - '0';
 
-    if (number < 0 || number > 3)
+    if (number < 0 || number > 4)
     {
         printf("Invalid network type\n");
         return;
@@ -844,6 +849,7 @@ void unselect_network()
     printf("IP     : 0\n");
     printf("GATT   : 1\n");
     printf("RFCOMM : 2\n");
+    printf("TCP    : 4\n");
     printf("select : ");
 
     char buf[MAX_BUF_LEN] = { 0 };
@@ -854,7 +860,7 @@ void unselect_network()
 
     int number = buf[0] - '0';
 
-    if (number < 0 || number > 3)
+    if (number < 0 || number > 4)
     {
         printf("Invalid network type\n");
         return;
@@ -1311,6 +1317,7 @@ CAResult_t get_network_type()
     printf("IP     : 0\n");
     printf("GATT   : 1\n");
     printf("RFCOMM : 2\n");
+    printf("TCP    : 4\n");
     printf("select : ");
 
     char buf[MAX_BUF_LEN] = { 0 };
@@ -1320,7 +1327,7 @@ CAResult_t get_network_type()
     }
 
     int number = buf[0] - '0';
-    if (0 > number || 2 < number)
+    if (0 > number || 4 < number)
     {
         printf("\nInvalid Network type");
         return CA_NOT_SUPPORTED;
@@ -1372,6 +1379,12 @@ void parse_coap_uri(const char* uri, addressSet_t* address, CATransportFlags_t *
         startIndex = COAP_PREFIX_LEN;
         *flags = CA_IPV4;
     }
+    else if (strncmp(COAP_TCP_PREFIX, uri, COAP_TCP_PREFIX_LEN) == 0)
+    {
+        printf("uri has '%s' prefix\n", COAP_TCP_PREFIX);
+        startIndex = COAP_TCP_PREFIX_LEN;
+        *flags = CA_IPV4;
+    }
 
     // #2. copy uri for parse
     int32_t len = strlen(uri) - startIndex;
index 8c4309c..367590a 100755 (executable)
@@ -112,9 +112,6 @@ env.AppendUnique(CA_SRC = ca_common_src)
 
 if 'ALL' in ca_transport:
                transports = [ 'ip_adapter', 'bt_edr_adapter', 'bt_le_adapter']
-               if ca_os == 'linux':
-                       if with_tcp:
-                               transports.append ('tcp_adapter')
                if with_ra:
                                transports.append ('ra_adapter')
                env.SConscript(dirs = [
@@ -129,6 +126,9 @@ if 'BT' in ca_transport:
 if 'BLE' in ca_transport:
        env.SConscript(os.path.join(ca_path, 'bt_le_adapter/SConscript'))
 
+if ca_os in ['linux', 'tizen']:
+       if with_tcp == True:
+               env.SConscript(os.path.join(ca_path, 'tcp_adapter/SConscript'))
 
 print "Include path is %s" % env.get('CPPPATH')
 print "Files path is %s" % env.get('CA_SRC')
index 5e55c1f..d2dcf44 100644 (file)
@@ -15,7 +15,7 @@ src_dir = './tcp_adapter/'
 
 # Source files to build common for all platforms
 common_files = None
-if target_os == 'linux':
+if target_os in ['linux', 'tizen']:
     common_files = [
         os.path.join(src_dir, 'catcpadapter.c'),
         os.path.join(src_dir, 'catcpserver.c') ]