ua_network_pubsub_udp.c 19 KB

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