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 = 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 #endif /* ZEPHYR_SUBSYS_LORAWAN_SERVICES_LORAWAN_SERVICES_H_ */
62