1 /* service-tracker.h 2 * 3 * Copyright (c) 2023 Apple Inc. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * This file contains general support definitions for the Off-Mesh Routable 18 * (OMR) prefix publisher state machine. 19 */ 20 21 #ifndef __THREAD_SERVICE_H__ 22 #define __THREAD_SERVICE_H__ 1 23 24 typedef struct thread_service thread_service_t; 25 typedef struct probe_state probe_state_t; 26 27 typedef enum { 28 add_complete, 29 delete_complete, 30 add_failed, 31 delete_failed, 32 add_pending, 33 delete_pending, 34 want_add, 35 want_delete, 36 } thread_service_publication_state_t; 37 38 struct thread_pref_id { 39 uint8_t partition_id[4]; // Partition id on which this prefix is claimed 40 uint8_t prefix[5]; // 40-bit ULA prefix identifier (no need to keep the whole prefix) 41 }; 42 43 struct thread_unicast_service { 44 struct in6_addr address; // IPv6 address on which service is offered 45 uint8_t port[2]; // Port (network byte order) 46 bool anycast_also_present; // True if the RLOC16 advertising this service is also advertising anycast 47 }; 48 49 struct thread_anycast_service { 50 struct in6_addr address; // Anycast IPv6 address constructed from the service identifier and mesh-local prefix 51 uint8_t sequence_number; 52 }; 53 54 typedef enum { any_service, pref_id, unicast_service, anycast_service } thread_service_type_t; 55 56 struct thread_service { 57 int ref_count; 58 thread_service_t *NULLABLE next; 59 uint16_t rloc16; 60 uint8_t service_id; 61 thread_service_type_t service_type; 62 bool user, ncp, stable, ignore, checking; 63 bool previous_user, previous_ncp, previous_stable; 64 thread_service_publication_state_t publication_state; 65 time_t last_probe_time; 66 bool checked; // true if we've checked that this service is responding 67 bool responding; // true if we've checked, and it's responding; last_probe_time is when it responded 68 probe_state_t *NULLABLE probe_state; 69 union { 70 struct thread_pref_id pref_id; 71 struct thread_anycast_service anycast; 72 struct thread_unicast_service unicast; 73 } u; 74 }; 75 76 RELEASE_RETAIN_DECLS(thread_service); 77 #define thread_service_retain(watcher) thread_service_retain_(watcher, __FILE__, __LINE__) 78 #define thread_service_release(watcher) thread_service_release_(watcher, __FILE__, __LINE__) 79 void thread_service_list_release(thread_service_t *NONNULL *NULLABLE list_pointer); 80 #define thread_service_unicast_create(rloc16, address, port, service_id) \ 81 thread_service_unicast_create_(rloc16, address, port, service_id, __FILE__, __LINE__) 82 thread_service_t *NULLABLE thread_service_unicast_create_(uint16_t rloc16, uint8_t *NONNULL address, 83 uint8_t *NONNULL port, uint8_t service_id, 84 const char *NONNULL file, int line); 85 #define thread_service_anycast_create(rloc16, sequence_number, service_id) \ 86 thread_service_anycast_create_(rloc16, sequence_number, service_id, __FILE__, __LINE__) 87 thread_service_t *NULLABLE thread_service_anycast_create_(uint16_t rloc16, uint8_t sequence_number, 88 uint8_t service_id, const char *NONNULL file, int line); 89 #define thread_service_pref_id_create(rloc16, partition_id, prefix, service_id) \ 90 thread_service_pref_id_create_(rloc16, partition_id, prefix, service_id, __FILE__, __LINE__) 91 thread_service_t *NULLABLE thread_service_pref_id_create_(uint16_t rloc16, uint8_t *NONNULL partition_id, 92 uint8_t *NONNULL prefix, uint8_t service_id, 93 const char *NONNULL file, int line); 94 void thread_service_note(const char *NONNULL owner_id, thread_service_t *NONNULL service, 95 const char *NONNULL event_description); 96 const char *NONNULL thread_service_publication_state_name_get(thread_service_publication_state_t publication_state); 97 bool thread_service_equal(thread_service_t *NULLABLE a, thread_service_t *NULLABLE b); 98 #endif // __THREAD_SERVICE_H__ 99 100 // Local Variables: 101 // mode: C 102 // tab-width: 4 103 // c-file-style: "bsd" 104 // c-basic-offset: 4 105 // fill-column: 120 106 // indent-tabs-mode: nil 107 // End: 108