Lines Matching full:service
84 static int coap_service_remove_observer(const struct coap_service *service, in coap_service_remove_observer() argument
93 obs = coap_find_observer(service->data->observers, MAX_OBSERVERS, addr, token, tkl); in coap_service_remove_observer()
96 obs = coap_find_observer_by_token(service->data->observers, MAX_OBSERVERS, token, in coap_service_remove_observer()
99 obs = coap_find_observer_by_addr(service->data->observers, MAX_OBSERVERS, addr); in coap_service_remove_observer()
110 COAP_SERVICE_FOREACH_RESOURCE(service, it) { in coap_service_remove_observer()
130 struct coap_service *service = NULL; in coap_server_process() local
159 /* Find the active service */ in coap_server_process()
162 service = svc; in coap_server_process()
166 if (service == NULL) { in coap_server_process()
173 pending = coap_pending_received(&request, service->data->pending, MAX_PENDINGS); in coap_server_process()
181 coap_service_remove_observer(service, NULL, &client_addr, token, tkl); in coap_server_process()
206 ret = coap_well_known_core_get_len(service->res_begin, in coap_server_process()
207 COAP_SERVICE_RESOURCE_COUNT(service), in coap_server_process()
211 LOG_ERR("Failed to build well known core for %s (%d)", service->name, ret); in coap_server_process()
215 ret = coap_service_send(service, &response, &client_addr, client_addr_len, NULL); in coap_server_process()
217 ret = coap_handle_request_len(&request, service->res_begin, in coap_server_process()
218 COAP_SERVICE_RESOURCE_COUNT(service), in coap_server_process()
246 ret = coap_service_send(service, &ack, &client_addr, client_addr_len, NULL); in coap_server_process()
265 COAP_SERVICE_FOREACH(service) { in coap_server_retransmit()
266 if (service->data->sock_fd < 0) { in coap_server_retransmit()
270 pending = coap_pending_next_to_expire(service->data->pending, MAX_PENDINGS); in coap_server_retransmit()
283 ret = zsock_sendto(service->data->sock_fd, pending->data, pending->len, 0, in coap_server_retransmit()
287 service->name, ret); in coap_server_retransmit()
291 LOG_WRN("Packet retransmission failed for %s", service->name); in coap_server_retransmit()
293 coap_service_remove_observer(service, NULL, &pending->addr, NULL, 0U); in coap_server_retransmit()
339 static inline bool coap_service_in_section(const struct coap_service *service) in coap_service_in_section() argument
344 return STRUCT_SECTION_START(coap_service) <= service && in coap_service_in_section()
345 STRUCT_SECTION_END(coap_service) > service; in coap_service_in_section()
348 static inline void coap_service_raise_event(const struct coap_service *service, uint32_t mgmt_event) in coap_service_raise_event() argument
352 .service = service, in coap_service_raise_event()
357 ARG_UNUSED(service); in coap_service_raise_event()
363 int coap_service_start(const struct coap_service *service) in coap_service_start() argument
378 if (!coap_service_in_section(service)) { in coap_service_start()
385 if (service->data->sock_fd >= 0) { in coap_service_start()
392 if (IS_ENABLED(CONFIG_NET_IPV6) && service->host != NULL && in coap_service_start()
393 zsock_inet_pton(AF_INET6, service->host, &addr_ptrs.addr6->sin6_addr) == 1) { in coap_service_start()
399 addr_ptrs.addr6->sin6_port = htons(*service->port); in coap_service_start()
400 } else if (IS_ENABLED(CONFIG_NET_IPV4) && service->host != NULL && in coap_service_start()
401 zsock_inet_pton(AF_INET, service->host, &addr_ptrs.addr4->sin_addr) == 1) { in coap_service_start()
407 addr_ptrs.addr4->sin_port = htons(*service->port); in coap_service_start()
414 addr_ptrs.addr6->sin6_port = htons(*service->port); in coap_service_start()
420 addr_ptrs.addr4->sin_port = htons(*service->port); in coap_service_start()
426 service->data->sock_fd = zsock_socket(af, SOCK_DGRAM, IPPROTO_UDP); in coap_service_start()
427 if (service->data->sock_fd < 0) { in coap_service_start()
432 ret = zsock_fcntl(service->data->sock_fd, F_SETFL, O_NONBLOCK); in coap_service_start()
438 ret = zsock_bind(service->data->sock_fd, addr_ptrs.addr, len); in coap_service_start()
444 if (*service->port == 0) { in coap_service_start()
447 ret = zsock_getsockname(service->data->sock_fd, addr_ptrs.addr, &len); in coap_service_start()
453 *service->port = addr_ptrs.addr6->sin6_port; in coap_service_start()
455 *service->port = addr_ptrs.addr4->sin_port; in coap_service_start()
464 coap_service_raise_event(service, NET_EVENT_COAP_SERVICE_STARTED); in coap_service_start()
469 (void)zsock_close(service->data->sock_fd); in coap_service_start()
470 service->data->sock_fd = -1; in coap_service_start()
477 int coap_service_stop(const struct coap_service *service) in coap_service_stop() argument
481 if (!coap_service_in_section(service)) { in coap_service_stop()
488 if (service->data->sock_fd < 0) { in coap_service_stop()
494 ret = zsock_close(service->data->sock_fd); in coap_service_stop()
495 service->data->sock_fd = -1; in coap_service_stop()
499 coap_service_raise_event(service, NET_EVENT_COAP_SERVICE_STOPPED); in coap_service_stop()
504 int coap_service_is_running(const struct coap_service *service) in coap_service_is_running() argument
508 if (!coap_service_in_section(service)) { in coap_service_is_running()
515 ret = (service->data->sock_fd < 0) ? 0 : 1; in coap_service_is_running()
522 int coap_service_send(const struct coap_service *service, const struct coap_packet *cpkt, in coap_service_send() argument
528 if (!coap_service_in_section(service)) { in coap_service_send()
535 if (service->data->sock_fd < 0) { in coap_service_send()
545 struct coap_pending *pending = coap_pending_next_unused(service->data->pending, in coap_service_send()
549 LOG_WRN("No pending message available for %s", service->name); in coap_service_send()
555 LOG_WRN("Failed to init pending message for %s (%d)", service->name, ret); in coap_service_send()
562 LOG_WRN("Failed to allocate pending message data for %s", service->name); in coap_service_send()
577 ret = zsock_sendto(service->data->sock_fd, cpkt->data, cpkt->offset, 0, addr, addr_len); in coap_service_send()
591 /* Find owning service */ in coap_resource_send()
604 const struct coap_service *service = NULL; in coap_resource_parse_observe() local
618 /* Find owning service */ in coap_resource_parse_observe()
621 service = svc; in coap_resource_parse_observe()
626 if (service == NULL) { in coap_resource_parse_observe()
641 observer = coap_find_observer(service->data->observers, MAX_OBSERVERS, addr, token, in coap_resource_parse_observe()
649 observer = coap_observer_next_unused(service->data->observers, MAX_OBSERVERS); in coap_resource_parse_observe()
658 ret = coap_service_remove_observer(service, resource, addr, token, tkl); in coap_resource_parse_observe()
674 const struct coap_service *service = NULL; in coap_resource_remove_observer() local
677 /* Find owning service */ in coap_resource_remove_observer()
680 service = svc; in coap_resource_remove_observer()
685 if (service == NULL) { in coap_resource_remove_observer()
690 ret = coap_service_remove_observer(service, resource, addr, token, token_len); in coap_resource_remove_observer()
750 LOG_ERR("Failed to autostart service %s (%d)", svc->name, ret); in coap_server_thread()