1 /* 2 * Copyright (c) 2022 Martin Jäger <martin@libre.solar> 3 * Copyright (c) 2022 tado GmbH 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #ifndef ZEPHYR_SUBSYS_LORAWAN_SERVICES_LORAWAN_SERVICES_H_ 9 #define ZEPHYR_SUBSYS_LORAWAN_SERVICES_LORAWAN_SERVICES_H_ 10 11 #include <zephyr/kernel.h> 12 #include <zephyr/lorawan/lorawan.h> 13 14 /** 15 * Unique package identifiers used for LoRaWAN services. 16 */ 17 enum lorawan_package_id { 18 LORAWAN_PACKAGE_ID_COMPLIANCE = 0, 19 LORAWAN_PACKAGE_ID_CLOCK_SYNC = 1, 20 LORAWAN_PACKAGE_ID_REMOTE_MULTICAST_SETUP = 2, 21 LORAWAN_PACKAGE_ID_FRAG_TRANSPORT_BLOCK = 3, 22 }; 23 24 /** 25 * Default ports used for LoRaWAN services. 26 */ 27 enum lorawan_services_port { 28 LORAWAN_PORT_MULTICAST_SETUP = 200, 29 LORAWAN_PORT_FRAG_TRANSPORT = 201, 30 LORAWAN_PORT_CLOCK_SYNC = 202, 31 }; 32 33 /** 34 * @brief Send unconfirmed LoRaWAN uplink message after the specified timeout 35 * 36 * @param port Port to be used for sending data. 37 * @param data Data buffer to be sent. 38 * @param len Length of the data to be sent. Maximum length of the 39 * buffer is 18 bytes. 40 * @param timeout Relative timeout in milliseconds when the uplink message 41 * should be scheduled. 42 * 43 * @return 0 if message was successfully queued, negative errno otherwise. 44 */ 45 int lorawan_services_schedule_uplink(uint8_t port, uint8_t *data, uint8_t len, uint32_t timeout); 46 47 /** 48 * @brief Reschedule a delayable work item to the LoRaWAN services work queue 49 * 50 * This work queue is used to schedule the uplink messages, but can be used by 51 * any of the services for internal tasks. 52 * 53 * @param dwork pointer to the delayable work item. 54 * @param delay the time to wait before submitting the work item. 55 56 * @returns Result of call to k_work_reschedule_for_queue() 57 */ 58 int lorawan_services_reschedule_work(struct k_work_delayable *dwork, k_timeout_t delay); 59 60 61 /** 62 * @brief Start a class C session 63 * 64 * If there is already an ongoing class C session, only the internal counter of 65 * active sessions is incremented. 66 * 67 * @returns Number of active sessions if successful or negative errno otherwise. 68 */ 69 int lorawan_services_class_c_start(void); 70 71 /** 72 * @brief Stop class C session and revert to class A 73 * 74 * If there is more than one class C session ongoing, only the internal counter 75 * of active sessions is decremented. 76 * 77 * @returns Number of active sessions if successful or negative errno otherwise. 78 */ 79 int lorawan_services_class_c_stop(void); 80 81 /** 82 * @brief Retrieve number of active sessions 83 * 84 * Can be used to determine if sessions are ongoing and avoid disturbing an 85 * ongoing session by sending out unnecessary messages. 86 * 87 * @returns Number of active class C sessions. 88 */ 89 int lorawan_services_class_c_active(void); 90 91 #endif /* ZEPHYR_SUBSYS_LORAWAN_SERVICES_LORAWAN_SERVICES_H_ */ 92