ua_network_pubsub_udp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright (c) 2017-2018 Fraunhofer IOSB (Author: Andreas Ebner)
  6. * Copyright 2018 (c) Jose Cabral, fortiss GmbH
  7. */
  8. #include "ua_plugin_network.h"
  9. #include "ua_network_pubsub_udp.h"
  10. #include "ua_log_stdout.h"
  11. //UDP multicast network layer specific internal data
  12. typedef struct {
  13. int ai_family; //Protocol family for socket. IPv4/IPv6
  14. struct sockaddr_storage *ai_addr; //https://msdn.microsoft.com/de-de/library/windows/desktop/ms740496(v=vs.85).aspx
  15. UA_UInt32 messageTTL;
  16. UA_Boolean enableLoopback;
  17. UA_Boolean enableReuse;
  18. } UA_PubSubChannelDataUDPMC;
  19. /**
  20. * Open communication socket based on the connectionConfig. Protocol specific parameters are
  21. * provided within the connectionConfig as KeyValuePair.
  22. * Currently supported options: "ttl" , "loopback", "reuse"
  23. *
  24. * @return ref to created channel, NULL on error
  25. */
  26. static UA_PubSubChannel *
  27. UA_PubSubChannelUDPMC_open(const UA_PubSubConnectionConfig *connectionConfig) {
  28. UA_initialize_architecture_network();
  29. UA_NetworkAddressUrlDataType address;
  30. if(UA_Variant_hasScalarType(&connectionConfig->address, &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE])){
  31. address = *(UA_NetworkAddressUrlDataType *)connectionConfig->address.data;
  32. } else {
  33. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation failed. Invalid Address.");
  34. return NULL;
  35. }
  36. //allocate and init memory for the UDP multicast specific internal data
  37. UA_PubSubChannelDataUDPMC * channelDataUDPMC =
  38. (UA_PubSubChannelDataUDPMC *) UA_calloc(1, (sizeof(UA_PubSubChannelDataUDPMC)));
  39. if(!channelDataUDPMC){
  40. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation failed. Out of memory.");
  41. return NULL;
  42. }
  43. //set default values
  44. memcpy(channelDataUDPMC, &(UA_PubSubChannelDataUDPMC){0, NULL, 255, UA_TRUE, UA_TRUE}, sizeof(UA_PubSubChannelDataUDPMC));
  45. //iterate over the given KeyValuePair paramters
  46. UA_String ttlParam = UA_STRING("ttl"), loopbackParam = UA_STRING("loopback"), reuseParam = UA_STRING("reuse");
  47. for(size_t i = 0; i < connectionConfig->connectionPropertiesSize; i++){
  48. if(UA_String_equal(&connectionConfig->connectionProperties[i].key.name, &ttlParam)){
  49. if(UA_Variant_hasScalarType(&connectionConfig->connectionProperties[i].value, &UA_TYPES[UA_TYPES_UINT32])){
  50. channelDataUDPMC->messageTTL = *(UA_UInt32 *) connectionConfig->connectionProperties[i].value.data;
  51. }
  52. } else if(UA_String_equal(&connectionConfig->connectionProperties[i].key.name, &loopbackParam)){
  53. if(UA_Variant_hasScalarType(&connectionConfig->connectionProperties[i].value, &UA_TYPES[UA_TYPES_BOOLEAN])){
  54. channelDataUDPMC->enableLoopback = *(UA_Boolean *) connectionConfig->connectionProperties[i].value.data;
  55. }
  56. } else if(UA_String_equal(&connectionConfig->connectionProperties[i].key.name, &reuseParam)){
  57. if(UA_Variant_hasScalarType(&connectionConfig->connectionProperties[i].value, &UA_TYPES[UA_TYPES_BOOLEAN])){
  58. channelDataUDPMC->enableReuse = *(UA_Boolean *) connectionConfig->connectionProperties[i].value.data;
  59. }
  60. } else {
  61. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation. Unknown connection parameter.");
  62. }
  63. }
  64. UA_PubSubChannel *newChannel = (UA_PubSubChannel *) UA_calloc(1, sizeof(UA_PubSubChannel));
  65. if(!newChannel){
  66. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection creation failed. Out of memory.");
  67. UA_free(channelDataUDPMC);
  68. return NULL;
  69. }
  70. struct addrinfo hints, *rp, *requestResult = NULL;
  71. memset(&hints, 0, sizeof hints);
  72. hints.ai_family = AF_UNSPEC;
  73. hints.ai_socktype = SOCK_DGRAM;
  74. hints.ai_flags = 0;
  75. hints.ai_protocol = 0;
  76. UA_String hostname, path;
  77. UA_UInt16 networkPort;
  78. if(UA_parseEndpointUrl(&address.url, &hostname, &networkPort, &path) != UA_STATUSCODE_GOOD){
  79. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  80. "PubSub Connection creation failed. Invalid URL.");
  81. UA_free(channelDataUDPMC);
  82. UA_free(newChannel);
  83. return NULL;
  84. }
  85. if(hostname.length > 512) {
  86. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  87. "PubSub Connection creation failed. URL maximum length is 512.");
  88. UA_free(channelDataUDPMC);
  89. UA_free(newChannel);
  90. return NULL;
  91. }
  92. UA_STACKARRAY(char, addressAsChar, sizeof(char) * hostname.length +1);
  93. memcpy(addressAsChar, hostname.data, hostname.length);
  94. addressAsChar[hostname.length] = 0;
  95. char port[6];
  96. sprintf(port, "%u", networkPort);
  97. if(UA_getaddrinfo(addressAsChar, port, &hints, &requestResult) != 0) {
  98. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  99. "PubSub Connection creation failed. Internal error.");
  100. UA_free(channelDataUDPMC);
  101. UA_free(newChannel);
  102. return NULL;
  103. }
  104. //check if the ip address is a multicast address
  105. if(requestResult->ai_family == PF_INET){
  106. struct in_addr imr_interface;
  107. UA_inet_pton(AF_INET, addressAsChar, &imr_interface);
  108. if((UA_ntohl(imr_interface.s_addr) & 0xF0000000) != 0xE0000000){
  109. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  110. "PubSub Connection creation failed. No multicast address.");
  111. UA_freeaddrinfo(requestResult);
  112. UA_free(channelDataUDPMC);
  113. UA_free(newChannel);
  114. return NULL;
  115. }
  116. } else {
  117. //TODO check if ipv6 addrr is multicast address.
  118. }
  119. for(rp = requestResult; rp != NULL; rp = rp->ai_next){
  120. newChannel->sockfd = UA_socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
  121. if(newChannel->sockfd != UA_INVALID_SOCKET){
  122. break; /*success*/
  123. }
  124. }
  125. if(!rp){
  126. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  127. "PubSub Connection creation failed. Internal error.");
  128. UA_freeaddrinfo(requestResult);
  129. UA_free(channelDataUDPMC);
  130. UA_free(newChannel);
  131. return NULL;
  132. }
  133. channelDataUDPMC->ai_family = rp->ai_family;
  134. channelDataUDPMC->ai_addr = (struct sockaddr_storage *) UA_calloc(1, sizeof(struct sockaddr_storage));
  135. if(!channelDataUDPMC->ai_addr){
  136. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  137. "PubSub Connection creation failed. Out of memory.");
  138. UA_close(newChannel->sockfd);
  139. UA_freeaddrinfo(requestResult);
  140. UA_free(channelDataUDPMC);
  141. UA_free(newChannel);
  142. return NULL;
  143. }
  144. memcpy(channelDataUDPMC->ai_addr, rp->ai_addr, sizeof(*rp->ai_addr));
  145. //link channel and internal channel data
  146. newChannel->handle = channelDataUDPMC;
  147. //Set loop back data to your host
  148. #if UA_IPV6
  149. if(UA_setsockopt(newChannel->sockfd,
  150. requestResult->ai_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP,
  151. requestResult->ai_family == PF_INET6 ? IPV6_MULTICAST_LOOP : IP_MULTICAST_LOOP,
  152. (const char *)&channelDataUDPMC->enableLoopback, sizeof (channelDataUDPMC->enableLoopback))
  153. #else
  154. if(UA_setsockopt(newChannel->sockfd,
  155. IPPROTO_IP,
  156. IP_MULTICAST_LOOP,
  157. (const char *)&channelDataUDPMC->enableLoopback, sizeof (channelDataUDPMC->enableLoopback))
  158. #endif
  159. < 0) {
  160. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  161. "PubSub Connection creation failed. Loopback setup failed.");
  162. UA_close(newChannel->sockfd);
  163. UA_freeaddrinfo(requestResult);
  164. UA_free(channelDataUDPMC);
  165. UA_free(newChannel);
  166. return NULL;
  167. }
  168. //Set Time to live (TTL). Value of 1 prevent forward beyond the local network.
  169. #if UA_IPV6
  170. if(UA_setsockopt(newChannel->sockfd,
  171. requestResult->ai_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP,
  172. requestResult->ai_family == PF_INET6 ? IPV6_MULTICAST_HOPS : IP_MULTICAST_TTL,
  173. (const char *)&channelDataUDPMC->messageTTL, sizeof(channelDataUDPMC->messageTTL))
  174. #else
  175. if(UA_setsockopt(newChannel->sockfd,
  176. IPPROTO_IP,
  177. IP_MULTICAST_TTL,
  178. (const char *)&channelDataUDPMC->messageTTL, sizeof(channelDataUDPMC->messageTTL))
  179. #endif
  180. < 0) {
  181. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  182. "PubSub Connection creation problem. Time to live setup failed.");
  183. }
  184. //Set reuse address -> enables sharing of the same listening address on different sockets.
  185. if(channelDataUDPMC->enableReuse){
  186. int enableReuse = 1;
  187. if(UA_setsockopt(newChannel->sockfd,
  188. SOL_SOCKET, SO_REUSEADDR,
  189. (const char*)&enableReuse, sizeof(enableReuse)) < 0){
  190. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  191. "PubSub Connection creation problem. Reuse address setup failed.");
  192. }
  193. }
  194. //Set the physical interface for outgoing traffic
  195. if(address.networkInterface.length > 0){
  196. UA_STACKARRAY(char, interfaceAsChar, sizeof(char) * address.networkInterface.length + 1);
  197. memcpy(interfaceAsChar, address.networkInterface.data, address.networkInterface.length);
  198. interfaceAsChar[address.networkInterface.length] = 0;
  199. enum{
  200. IPv4,
  201. #if UA_IPV6
  202. IPv6,
  203. #endif
  204. INVALID
  205. } ipVersion;
  206. union {
  207. struct ip_mreq ipv4;
  208. #if UA_IPV6
  209. struct ipv6_mreq ipv6;
  210. #endif
  211. } group;
  212. if(UA_inet_pton(AF_INET, interfaceAsChar, &group.ipv4.imr_interface)){
  213. ipVersion = IPv4;
  214. #if UA_IPV6
  215. } else if (UA_inet_pton(AF_INET6, interfaceAsChar, &group.ipv6.ipv6mr_multiaddr)){
  216. group.ipv6.ipv6mr_interface = UA_if_nametoindex(interfaceAsChar);
  217. ipVersion = IPv6;
  218. #endif
  219. } else {
  220. ipVersion = INVALID;
  221. }
  222. if(ipVersion == INVALID ||
  223. #if UA_IPV6
  224. UA_setsockopt(newChannel->sockfd,
  225. requestResult->ai_family == PF_INET6 ? IPPROTO_IPV6 : IPPROTO_IP,
  226. requestResult->ai_family == PF_INET6 ? IPV6_MULTICAST_IF : IP_MULTICAST_IF,
  227. ipVersion == IPv6 ? (const void *) &group.ipv6.ipv6mr_interface : &group.ipv4.imr_interface,
  228. ipVersion == IPv6 ? sizeof(group.ipv6.ipv6mr_interface) : sizeof(struct in_addr))
  229. #else
  230. UA_setsockopt(newChannel->sockfd,
  231. IPPROTO_IP,
  232. IP_MULTICAST_IF,
  233. &group.ipv4.imr_interface,
  234. sizeof(struct in_addr))
  235. #endif
  236. < 0) {
  237. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
  238. "PubSub Connection creation problem. Interface selection failed.");
  239. };
  240. }
  241. UA_freeaddrinfo(requestResult);
  242. newChannel->state = UA_PUBSUB_CHANNEL_PUB;
  243. return newChannel;
  244. }
  245. /**
  246. * Subscribe to a given address.
  247. *
  248. * @return UA_STATUSCODE_GOOD on success
  249. */
  250. static UA_StatusCode
  251. UA_PubSubChannelUDPMC_regist(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings) {
  252. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB || channel->state == UA_PUBSUB_CHANNEL_RDY)){
  253. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  254. return UA_STATUSCODE_BADINTERNALERROR;
  255. }
  256. UA_PubSubChannelDataUDPMC * connectionConfig = (UA_PubSubChannelDataUDPMC *) channel->handle;
  257. if(connectionConfig->ai_family == PF_INET){//IPv4 handling
  258. struct sockaddr_in addr;
  259. memcpy(&addr, connectionConfig->ai_addr, sizeof(struct sockaddr_in));
  260. addr.sin_addr.s_addr = INADDR_ANY;
  261. if (UA_bind(channel->sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0){
  262. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  263. return UA_STATUSCODE_BADINTERNALERROR;
  264. }
  265. struct ip_mreq groupV4;
  266. memcpy(&groupV4.imr_multiaddr, &((const struct sockaddr_in *)connectionConfig->ai_addr)->sin_addr, sizeof(struct ip_mreq));
  267. groupV4.imr_interface.s_addr = UA_htonl(INADDR_ANY);
  268. //multihomed hosts can join several groups on different IF, INADDR_ANY -> kernel decides
  269. if(UA_setsockopt(channel->sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &groupV4, sizeof(groupV4)) != 0){
  270. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  271. return UA_STATUSCODE_BADINTERNALERROR;
  272. }
  273. #if UA_IPV6
  274. } else if (connectionConfig->ai_family == PF_INET6) {//IPv6 handling
  275. //TODO implement regist for IPv6
  276. #endif
  277. } else {
  278. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection regist failed.");
  279. return UA_STATUSCODE_BADINTERNALERROR;
  280. }
  281. return UA_STATUSCODE_GOOD;
  282. }
  283. /**
  284. * Remove current subscription.
  285. *
  286. * @return UA_STATUSCODE_GOOD on success
  287. */
  288. static UA_StatusCode
  289. UA_PubSubChannelUDPMC_unregist(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettings) {
  290. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB_SUB || channel->state == UA_PUBSUB_CHANNEL_SUB)){
  291. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
  292. return UA_STATUSCODE_BADINTERNALERROR;
  293. }
  294. UA_PubSubChannelDataUDPMC * connectionConfig = (UA_PubSubChannelDataUDPMC *) channel->handle;
  295. if(connectionConfig->ai_family == PF_INET){//IPv4 handling
  296. struct ip_mreq groupV4;
  297. memcpy(&groupV4.imr_multiaddr, &((const struct sockaddr_in *)connectionConfig->ai_addr)->sin_addr, sizeof(struct ip_mreq));
  298. groupV4.imr_interface.s_addr = UA_htonl(INADDR_ANY);
  299. if(UA_setsockopt(channel->sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *) &groupV4, sizeof(groupV4)) != 0){
  300. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
  301. return UA_STATUSCODE_BADINTERNALERROR;
  302. }
  303. #if UA_IPV6
  304. } else if (connectionConfig->ai_family == PF_INET6) {//IPv6 handling
  305. //TODO implement unregist for IPv6
  306. #endif
  307. } else {
  308. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection unregist failed.");
  309. return UA_STATUSCODE_BADINTERNALERROR;
  310. }
  311. return UA_STATUSCODE_GOOD;
  312. }
  313. /**
  314. * Send messages to the connection defined address
  315. *
  316. * @return UA_STATUSCODE_GOOD if success
  317. */
  318. static UA_StatusCode
  319. UA_PubSubChannelUDPMC_send(UA_PubSubChannel *channel, UA_ExtensionObject *transportSettigns, const UA_ByteString *buf) {
  320. UA_PubSubChannelDataUDPMC *channelConfigUDPMC = (UA_PubSubChannelDataUDPMC *) channel->handle;
  321. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB || channel->state == UA_PUBSUB_CHANNEL_PUB_SUB)){
  322. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection sending failed. Invalid state.");
  323. return UA_STATUSCODE_BADINTERNALERROR;
  324. }
  325. //TODO evalute: chunk messages or check against MTU?
  326. long nWritten = 0;
  327. while (nWritten < (long)buf->length) {
  328. long n = (long)UA_sendto(channel->sockfd, buf->data, buf->length, 0,
  329. (struct sockaddr *) channelConfigUDPMC->ai_addr, sizeof(struct sockaddr_storage));
  330. if(n == -1L) {
  331. UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection sending failed.");
  332. return UA_STATUSCODE_BADINTERNALERROR;
  333. }
  334. nWritten += n;
  335. }
  336. return UA_STATUSCODE_GOOD;
  337. }
  338. /**
  339. * Receive messages. The regist function should be called before.
  340. *
  341. * @param timeout in usec | on windows platforms are only multiples of 1000usec possible
  342. * @return
  343. */
  344. static UA_StatusCode
  345. UA_PubSubChannelUDPMC_receive(UA_PubSubChannel *channel, UA_ByteString *message, UA_ExtensionObject *transportSettigns, UA_UInt32 timeout){
  346. if(!(channel->state == UA_PUBSUB_CHANNEL_PUB || channel->state == UA_PUBSUB_CHANNEL_PUB_SUB)) {
  347. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection receive failed. Invalid state.");
  348. return UA_STATUSCODE_BADINTERNALERROR;
  349. }
  350. UA_PubSubChannelDataUDPMC *channelConfigUDPMC = (UA_PubSubChannelDataUDPMC *) channel->handle;
  351. if(timeout > 0) {
  352. fd_set fdset;
  353. FD_ZERO(&fdset);
  354. UA_fd_set(channel->sockfd, &fdset);
  355. struct timeval tmptv = {(long int)(timeout / 1000000),
  356. (long int)(timeout % 1000000)};
  357. int resultsize = UA_select(channel->sockfd+1, &fdset, NULL,
  358. NULL, &tmptv);
  359. if(resultsize == 0) {
  360. message->length = 0;
  361. return UA_STATUSCODE_GOODNONCRITICALTIMEOUT;
  362. }
  363. if (resultsize == -1) {
  364. message->length = 0;
  365. return UA_STATUSCODE_BADINTERNALERROR;
  366. }
  367. }
  368. if(channelConfigUDPMC->ai_family == PF_INET){
  369. ssize_t messageLength;
  370. messageLength = UA_recvfrom(channel->sockfd, message->data, message->length, 0, NULL, NULL);
  371. if(messageLength > 0){
  372. message->length = (size_t) messageLength;
  373. } else {
  374. message->length = 0;
  375. }
  376. #if UA_IPV6
  377. } else {
  378. //TODO implement recieve for IPv6
  379. #endif
  380. }
  381. return UA_STATUSCODE_GOOD;
  382. }
  383. /**
  384. * Close channel and free the channel data.
  385. *
  386. * @return UA_STATUSCODE_GOOD if success
  387. */
  388. static UA_StatusCode
  389. UA_PubSubChannelUDPMC_close(UA_PubSubChannel *channel) {
  390. UA_deinitialize_architecture_network();
  391. if(UA_close(channel->sockfd) != 0){
  392. UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "PubSub Connection delete failed.");
  393. return UA_STATUSCODE_BADINTERNALERROR;
  394. }
  395. //cleanup the internal NetworkLayer data
  396. UA_PubSubChannelDataUDPMC *networkLayerData = (UA_PubSubChannelDataUDPMC *) channel->handle;
  397. UA_free(networkLayerData->ai_addr);
  398. UA_free(networkLayerData);
  399. UA_free(channel);
  400. return UA_STATUSCODE_GOOD;
  401. }
  402. /**
  403. * Generate a new channel. based on the given configuration.
  404. *
  405. * @param connectionConfig connection configuration
  406. * @return ref to created channel, NULL on error
  407. */
  408. static UA_PubSubChannel *
  409. TransportLayerUDPMC_addChannel(UA_PubSubConnectionConfig *connectionConfig) {
  410. UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "PubSub channel requested");
  411. UA_PubSubChannel * pubSubChannel = UA_PubSubChannelUDPMC_open(connectionConfig);
  412. if(pubSubChannel){
  413. pubSubChannel->regist = UA_PubSubChannelUDPMC_regist;
  414. pubSubChannel->unregist = UA_PubSubChannelUDPMC_unregist;
  415. pubSubChannel->send = UA_PubSubChannelUDPMC_send;
  416. pubSubChannel->receive = UA_PubSubChannelUDPMC_receive;
  417. pubSubChannel->close = UA_PubSubChannelUDPMC_close;
  418. pubSubChannel->connectionConfig = connectionConfig;
  419. }
  420. return pubSubChannel;
  421. }
  422. //UDPMC channel factory
  423. UA_PubSubTransportLayer
  424. UA_PubSubTransportLayerUDPMP() {
  425. UA_PubSubTransportLayer pubSubTransportLayer;
  426. pubSubTransportLayer.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
  427. pubSubTransportLayer.createPubSubChannel = &TransportLayerUDPMC_addChannel;
  428. return pubSubTransportLayer;
  429. }