Commit d55f5839 authored by Uze Choi's avatar Uze Choi Committed by Gerrit Code Review

Merge "Merge Resource Directory into the master" into 1.0.0-dev

parents 529d886a f426c86c
......@@ -12,6 +12,8 @@ function build_all()
build_linux_secured $1 $2
build_linux_unsecured_with_ra $1 $2
build_linux_secured_with_ra $1 $2
build_linux_unsecured_with_rd $1 $2
build_linux_secured_with_rd $1 $2
fi
build_android $1 $2
......@@ -58,6 +60,18 @@ function build_linux_secured_with_ra()
scons RELEASE=$1 WITH_RA=1 SECURED=1 $2
}
function build_linux_unsecured_with_rd()
{
echo "*********** Build for linux With Resource Directory *************"
scons RELEASE=$1 WITH_RD=1 $2
}
function build_linux_secured_with_rd()
{
echo "*********** Build for linux With Resource Directory & Security ************"
scons RELEASE=$1 WITH_RD=1 SECURED=1 $2
}
function build_android()
{
# Note: for android, as oic-resource uses C++11 feature stoi and to_string,
......@@ -144,8 +158,8 @@ function help()
echo "Usage:"
echo " build:"
echo " `basename $0` <target_build>"
echo " Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_ra, linux_secured_with_ra, android, arduino, tizen, darwin"
echo " Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\" & \"linux_secured_with_ra\"."
echo " Allowed values for <target_build>: all, linux_unsecured, linux_secured, linux_unsecured_with_ra, linux_secured_with_ra, linux_unsecured_with_rd, linux_secured_with_rd, android, arduino, tizen, darwin"
echo " Note: \"linux\" will build \"linux_unsecured\", \"linux_secured\", \"linux_unsecured_with_ra\", \"linux_secured_with_ra\", \"linux_secured_with_rd\" & \"linux_unsecured_with_rd\"."
echo " Any selection will build both debug and release versions of all available targets in the scope you've"
echo " selected. To choose any specific command, please use the SCons commandline directly. Please refer"
echo " to [IOTIVITY_REPO]/Readme.scons.txt."
......@@ -188,6 +202,14 @@ then
then
build_linux_secured_with_ra true
build_linux_secured_with_ra false
elif [ $1 = 'linux_unsecured_with_rd' ]
then
build_linux_unsecured_with_rd true
build_linux_unsecured_with_rd false
elif [ $1 = 'linux_secured_with_rd' ]
then
build_linux_secured_with_rd true
build_linux_secured_with_rd false
elif [ $1 = 'android' ]
then
build_android true
......
......@@ -80,6 +80,7 @@ help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map
help_vars.Add(BoolVariable('WITH_RA', 'Build with Remote Access module', False))
help_vars.Add(BoolVariable('SIMULATOR', 'Build with simulator module', False))
help_vars.Add(EnumVariable('WITH_RD', 'Build including Resource Directory', '0', allowed_values=('0', '1')))
if target_os in targets_disallow_multitransport:
help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP']))
......
......@@ -128,7 +128,8 @@ liboctbstack_src = [
OCTBSTACK_SRC + 'occollection.c',
OCTBSTACK_SRC + 'oicgroup.c',
'logger/src/logger.c',
'ocrandom/src/ocrandom.c'
'ocrandom/src/ocrandom.c',
OCTBSTACK_SRC + "rdpayload.c"
]
liboctbstack_src.extend(env['cbor_files'])
......
......@@ -85,6 +85,13 @@ void CATerminate();
*/
CAResult_t CAStartListeningServer();
/**
* Stops the server from receiving the multicast traffic. This is used by sleeping
* device to not receives the multicast traffic.
* @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
*/
CAResult_t CAStopListeningServer();
/**
* Starts discovery servers.
* This API is used by resource required clients for listening multicast requests.
......
......@@ -58,6 +58,17 @@ typedef CAResult_t (*CAAdapterStart)();
*/
typedef CAResult_t (*CAAdapterStartListeningServer)();
/**
* Stopping listening server to not receive multicast search requests
* Transport Specific Behavior:
* WIFI/ETH Stops multicast server on all available IPs. This is required for the
* thin device that call this function once all local resources are pushed to the
* resource directory.
* @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
* ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
typedef CAResult_t (*CAAdapterStopListeningServer)();
/**
* for starting discovery servers for receiving multicast advertisements
* Transport Specific Behavior:
......@@ -134,6 +145,9 @@ typedef struct
/** Listening Server function address. */
CAAdapterStartListeningServer startListenServer;
/** Stops receiving the multicast traffic. */
CAAdapterStopListeningServer stopListenServer;
/** Discovery Server function address. **/
CAAdapterStartDiscoveryServer startDiscoveryServer;
......
......@@ -71,6 +71,14 @@ CAResult_t CAStartEDR();
*/
CAResult_t CAStartEDRListeningServer();
/**
* Stop listening server for receiving multicast search requests.
* Stop RFCOMM Server with prefixed UUID as per OIC specification.
*
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAStopEDRListeningServer();
/**
* Starting discovery server for receiving multicast advertisements.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
......
......@@ -78,6 +78,13 @@ CAResult_t CAStartEDR();
*/
CAResult_t CAStartEDRListeningServer();
/**
* @brief Stops listening server for receiving multicast search requests.
*
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAStopEDRListeningServer();
/**
* @brief Starts discovery server for receiving multicast advertisements.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
......
......@@ -129,6 +129,12 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u
*/
CAResult_t CAStartListeningServerAdapters();
/**
* Stop listening servers to receive search requests from clients.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAStopListeningServerAdapters();
/**
* Start discovery servers to receive advertisements from server.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
......
......@@ -112,6 +112,12 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u
*/
CAResult_t CAStartListeningServerAdapters();
/**
* @brief Stops listening servers to receive search requests from clients
* @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
*/
CAResult_t CAStopListeningServerAdapters();
/**
* @brief Start discovery servers to receive advertisements from server
* @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
......
......@@ -68,6 +68,14 @@ CAResult_t CAStartIP();
*/
CAResult_t CAStartIPListeningServer();
/**
* Stop listening server from receiving multicast search requests.
* Transport Specific Behavior:
* IP closes open multicast socket for a particular interface.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
CAResult_t CAStopIPListeningServer();
/**
* Start discovery servers for receiving multicast advertisements.
* Transport Specific Behavior:
......
......@@ -98,6 +98,23 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
*/
void CAIPStopServer();
/**
* Starts receiving the multicast traffic.
*
* This will be used in case sleepy device wants to start back receiving the multicast
* traffic.
*/
CAResult_t CAIPStartListenServer();
/**
* Stops the multicast traffic.
*
* This is to be used by the sleeping device to stop receiving multicast traffic.
* Once this is set no multicast traffic will be received. Device can still receive
* the unicast traffic.
*/
CAResult_t CAIPStopListenServer();
/**
* Set this callback for receiving data packets from peer devices.
*
......
......@@ -114,6 +114,12 @@ int32_t CASendRAMulticastData(const CAEndpoint_t *endpoint,
*/
CAResult_t CAStartRAListeningServer();
/**
* Stops listening server from receiving search requests.
* @return ::CA_NOT_SUPPORTED.
*/
CAResult_t CAStopRAListeningServer();
/**
* Start discovery servers for receiving advertisements.
* @return ::CA_NOT_SUPPORTED.
......
......@@ -77,6 +77,15 @@ CAResult_t CAStartTCP();
*/
CAResult_t CAStartTCPListeningServer();
/**
* Stops listening server from receiving connect requests.
* Transport Specific Behavior:
* TCP Stops Listening Server on a particular interface and prefixed port
* number and as per OIC Specification.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
CAResult_t CAStopTCPListeningServer();
/**
* Start discovery servers for receiving advertisements.
* Transport Specific Behavior:
......
......@@ -199,6 +199,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
CAConnectivityHandler_t handler;
handler.startAdapter = CAStartEDR;
handler.startListenServer = CAStartEDRListeningServer;
handler.stopListenServer = CAStopEDRListeningServer;
handler.startDiscoveryServer = CAStartEDRDiscoveryServer;
handler.sendData = CASendEDRUnicastData;
handler.sendDataToAll = CASendEDRMulticastData;
......@@ -268,6 +269,13 @@ CAResult_t CAStartEDRListeningServer()
return CAStartServer();
}
CAResult_t CAStopEDRListeningServer()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
return CAEDRServerStop();
}
CAResult_t CAStartEDRDiscoveryServer()
{
OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
......
......@@ -46,6 +46,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
CAConnectivityHandler_t handler = {
.startAdapter = CAStartEDR,
.startListenServer = CAStartEDRListeningServer,
.stopListenServer = CAStopEDRListeningServer,
.startDiscoveryServer = CAStartEDRDiscoveryServer,
.sendData = CASendEDRUnicastData,
.sendDataToAll = CASendEDRMulticastData,
......@@ -74,6 +75,13 @@ CAResult_t CAStartEDRListeningServer()
return CA_STATUS_OK;
}
CAResult_t CAStopEDRListeningServer()
{
OIC_LOG(DEBUG, TAG, "CAStopEDRListeningServer");
return CA_STATUS_OK;
}
CAResult_t CAStartEDRDiscoveryServer()
{
OIC_LOG(DEBUG, TAG, "CAStartEDRDiscoveryServer");
......
......@@ -1446,6 +1446,16 @@ static CAResult_t CAStartLE();
*/
static CAResult_t CAStartLEListeningServer();
/**
* Stops listening server from receiving multicast search requests.
*
* Transport Specific Behavior:
* LE Starts GATT Server with prefixed UUID and Characteristics
* per OIC Specification.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
static CAResult_t CAStopLEListeningServer();
/**
* Sarting discovery of servers for receiving multicast
* advertisements.
......@@ -1661,6 +1671,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
.startAdapter = CAStartLE,
.stopAdapter = CAStopLE,
.startListenServer = CAStartLEListeningServer,
.stopListenServer = CAStopLEListeningServer,
.startDiscoveryServer = CAStartLEDiscoveryServer,
.sendData = CASendLEUnicastData,
.sendDataToAll = CASendLEMulticastData,
......@@ -1778,6 +1789,12 @@ static CAResult_t CAStartLEListeningServer()
#endif
}
static CAResult_t CAStopLEListeningServer()
{
OIC_LOG(ERROR, CALEADAPTER_TAG, "Listen server stop not supported.");
return CA_NOT_SUPPORTED;
}
static CAResult_t CAStartLEDiscoveryServer()
{
OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
......
......@@ -99,6 +99,18 @@ CAResult_t CAStartListeningServer()
return CAStartListeningServerAdapters();
}
CAResult_t CAStopListeningServer()
{
OIC_LOG(DEBUG, TAG, "CAStopListeningServer");
if(!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
}
return CAStopListeningServerAdapters();
}
CAResult_t CAStartDiscoveryServer()
{
OIC_LOG(DEBUG, TAG, "CAStartDiscoveryServer");
......
......@@ -97,6 +97,7 @@ static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapt
if(handler.startAdapter == NULL ||
handler.startListenServer == NULL ||
handler.stopListenServer == NULL ||
handler.startDiscoveryServer == NULL ||
handler.sendData == NULL ||
handler.sendDataToAll == NULL ||
......@@ -503,6 +504,44 @@ CAResult_t CAStartListeningServerAdapters()
return CA_STATUS_OK;
}
CAResult_t CAStopListeningServerAdapters()
{
OIC_LOG(DEBUG, TAG, "IN");
u_arraylist_t *list = CAGetSelectedNetworkList();
if (!list)
{
OIC_LOG(ERROR, TAG, "No selected network");
return CA_STATUS_FAILED;
}
for (uint32_t i = 0; i < u_arraylist_length(list); i++)
{
void* ptrType = u_arraylist_get(list, i);
if(ptrType == NULL)
{
continue;
}
CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
int index = CAGetAdapterIndex(connType);
if (index == -1)
{
OIC_LOG(ERROR, TAG, "unknown connectivity type!");
continue;
}
if (g_adapterHandler[index].stopListenServer != NULL)
{
g_adapterHandler[index].stopListenServer();
}
}
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAStartDiscoveryServerAdapters()
{
OIC_LOG(DEBUG, TAG, "IN");
......
......@@ -42,6 +42,12 @@
// Length of the IP address decimal notation string
#define IPNAMESIZE (16)
/** Multicast IP address.*/
#define IPv4_MULTICAST "224.0.1.187"
/** Multicast Port.*/
#define IPv4_MULTICAST_PORT 5683
CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
const bool forceStart, int32_t *serverFD);
static CAResult_t CAArduinoRecvData(int32_t sockFd);
......@@ -146,7 +152,7 @@ CAResult_t CAIPStartServer()
OIC_LOG_V(ERROR, TAG, "Start unicast server failed[%d]", ret);
return ret;
}
ret = CAIPStartMulticastServer("0.0.0.0", "224.0.1.187", 5683);
ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
......@@ -173,6 +179,30 @@ CAResult_t CAIPStopMulticastServer()
return CA_STATUS_OK;
}
CAResult_t CAIPStartListenServer()
{
OIC_LOG(DEBUG, TAG, "IN");
CAResult_t ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
}
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAIPStopListenServer()
{
OIC_LOG(DEBUG, TAG, "IN");
CAResult_t ret = CAIPStopMulticastServer();
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Stop multicast failed[%d]", ret);
}
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void CAIPStopServer()
{
OIC_LOG(DEBUG, TAG, "IN");
......
......@@ -42,6 +42,12 @@
// Length of the IP address decimal notation string
#define IPNAMESIZE (16)
/** Multicast IP address.*/
#define IPv4_MULTICAST "224.0.1.187"
/** Multicast Port.*/
#define IPv4_MULTICAST_PORT 5683
// Start offsets based on end of received data buffer
#define IP_RECBUF_IPADDR_OFFSET (6)
#define IP_RECBUF_PORT_OFFSET (2)
......@@ -134,7 +140,7 @@ CAResult_t CAIPStartServer()
OIC_LOG_V(ERROR, TAG, "Start unicast server failed[%d]", ret);
return ret;
}
ret = CAIPStartMulticastServer("0.0.0.0", "224.0.1.187", 5683);
ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
......@@ -158,6 +164,21 @@ CAResult_t CAIPStopMulticastServer()
return CAIPStopUnicastServer();
}
CAResult_t CAIPStartListenServer()
{
CAResult_t ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
}
return ret;
}
CAResult_t CAIPStopListenServer()
{
return CAIPStopMulticastServer();
}
void CAIPStopServer()
{
OIC_LOG(DEBUG, TAG, "IN");
......@@ -294,4 +315,3 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
......@@ -273,6 +273,7 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
CAConnectivityHandler_t ipHandler;
ipHandler.startAdapter = CAStartIP;
ipHandler.startListenServer = CAStartIPListeningServer;
ipHandler.stopListenServer = CAStopIPListeningServer;
ipHandler.startDiscoveryServer = CAStartIPDiscoveryServer;
ipHandler.sendData = CASendIPUnicastData;
ipHandler.sendDataToAll = CASendIPMulticastData;
......@@ -331,7 +332,25 @@ CAResult_t CAStartIP()
CAResult_t CAStartIPListeningServer()
{
OIC_LOG(DEBUG, TAG, "IN");
CAResult_t ret = CAIPStartListenServer();
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Failed to start listening server![%d]", ret);
return ret;
}
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t CAStopIPListeningServer()
{
OIC_LOG(DEBUG, TAG, "IN");
CAResult_t ret = CAIPStopListenServer();
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(ERROR, TAG, "Failed to stop listening server![%d]", ret);
return ret;
}
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
......
......@@ -96,7 +96,6 @@ static CAIPExceptionCallback g_exceptionCallback;
static CAIPPacketReceivedCallback g_packetReceivedCallback;
static void CAHandleNetlink();
static void CAApplyInterfaces();
static void CAFindReadyMessage();
static void CASelectReturned(fd_set *readFds, int ret);
static void CAProcessNewInterface(CAInterface_t *ifchanged);
......@@ -479,7 +478,12 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
caglobals.ip.selectTimeout = CAGetPollingInterval(caglobals.ip.selectTimeout);
CAApplyInterfaces();
res = CAIPStartListenServer();
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "Failed to start listening server![%d]", res);
return res;
}
caglobals.ip.terminate = false;
res = ca_thread_pool_add_task(threadPool, CAReceiveHandler, NULL);
......@@ -590,13 +594,13 @@ static void applyMulticastToInterface6(uint32_t interface)
//applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressGlb, interface);
}
static void CAApplyInterfaces()
CAResult_t CAIPStartListenServer()
{
u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
if (!iflist)
{
OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
return;
return CA_STATUS_FAILED;
}
uint32_t len = u_arraylist_length(iflist);
......@@ -629,6 +633,53 @@ static void CAApplyInterfaces()
}
u_arraylist_destroy(iflist);
return CA_STATUS_OK;
}
CAResult_t CAIPStopListenServer()
{
u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
if (!iflist)
{
OIC_LOG_V(ERROR, TAG, "Get interface info failed: %s", strerror(errno));
return CA_STATUS_FAILED;
}
uint32_t len = u_arraylist_length(iflist);
OIC_LOG_V(DEBUG, TAG, "IP network interfaces found: %d", len);
for (uint32_t i = 0; i < len; i++)
{
CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
if (!ifitem)
{
continue;
}
if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
{
continue;
}
if (ifitem->family == AF_INET)
{
close(caglobals.ip.m4.fd);
close(caglobals.ip.m4s.fd);
caglobals.ip.m4.fd = -1;
caglobals.ip.m4s.fd = -1;
OIC_LOG_V(DEBUG, TAG, "IPv4 network interface: %s cloed", ifitem->name);
}
if (ifitem->family == AF_INET6)
{
close(caglobals.ip.m6.fd);
close(caglobals.ip.m6s.fd);
caglobals.ip.m6.fd = -1;
caglobals.ip.m6s.fd = -1;
OIC_LOG_V(DEBUG, TAG, "IPv6 network interface: %s", ifitem->name);