Skip to content

Commit 200c918

Browse files
moonlight83340yashi
authored andcommitted
csp_hook: add documentation for CSP hook functions
This commit adds detailed Doxygen-style comments to `csp_hooks.h` for all hook functions, including: - csp_input_hook - csp_output_hook - csp_reboot_hook - csp_shutdown_hook - csp_memfree_hook - csp_ps_hook - csp_panic - csp_crypto_encrypt / decrypt - csp_clock_get_time / set_time Each hook is now documented with parameter descriptions and return values, in order to improve developer understanding and assist with auto-generated documentation (e.g., Sphinx output). This improves maintainability and provides guidance to users who want to implement or override CSP hooks for their specific use cases. Signed-off-by: Gaetan Perrot <[email protected]>
1 parent c96137d commit 200c918

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

include/csp/csp_hooks.h

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/****************************************************************************
22
* **File:** csp/csp_hooks.h
33
*
4-
* **Description:** See Hooks in CSP
4+
* **Description:** Hooks that can be implemented in CSP, see Hooks in csp for more information
55
****************************************************************************/
66
#pragma once
77

@@ -12,22 +12,91 @@
1212
extern "C" {
1313
#endif
1414

15+
/**
16+
* Hook called when a packet is sent
17+
*
18+
* @param idout ID of the recipient
19+
* @param packet CSP packet to be sent
20+
* @param iface Outgoing interface
21+
* @param via Next hop address (if applicable)
22+
* @param from_me Whether the packet originates from this node
23+
*/
1524
void csp_output_hook(const csp_id_t * idout, csp_packet_t * packet, csp_iface_t * iface, uint16_t via, int from_me);
25+
26+
/**
27+
* Hook called when a packet is received
28+
*
29+
* @param iface Interface that received the packet
30+
* @param packet Received packet
31+
*/
1632
void csp_input_hook(csp_iface_t * iface, csp_packet_t * packet);
1733

34+
/**
35+
* Hook called for system reboot
36+
*/
1837
void csp_reboot_hook(void);
38+
39+
/**
40+
* Hook called for system shutdown
41+
*/
1942
void csp_shutdown_hook(void);
2043

44+
/**
45+
* Returns the available free memory
46+
* @return Free memory in bytes
47+
*/
2148
uint32_t csp_memfree_hook(void);
49+
50+
/**
51+
* Collects process information into a packet
52+
*
53+
* @param packet Packet to be filled with process info
54+
* @return Number of entries written
55+
*/
2256
unsigned int csp_ps_hook(csp_packet_t * packet);
2357

58+
/**
59+
* Called in case of a fatal error
60+
* This function must not return, and should reboot the system
61+
* or the program running CSP to recover responsiveness of the system.
62+
*
63+
* @param msg Error message
64+
*/
2465
void csp_panic(const char * msg);
2566

26-
/** Implement these, if you use csp_if_tun */
27-
int csp_crypto_decrypt(uint8_t * ciphertext_in, uint8_t ciphertext_len, uint8_t * msg_out); // Returns -1 for failure, length if ok
28-
int csp_crypto_encrypt(uint8_t * msg_begin, uint8_t msg_len, uint8_t * ciphertext_out); // Returns length of encrypted data
67+
/**
68+
* Decrypt a message (Implement these if you used csp_if_tun)
69+
*
70+
* @param ciphertext_in Encrypted input data
71+
* @param ciphertext_len Length of encrypted data
72+
* @param msg_out Output buffer for the decrypted message
73+
* @return Length of the decrypted data or an error code on failure
74+
*/
75+
int csp_crypto_decrypt(uint8_t * ciphertext_in, uint8_t ciphertext_len, uint8_t * msg_out);
2976

77+
/**
78+
* Encrypt a message (Implement these if you used csp_if_tun)
79+
*
80+
* @param msg_begin Plaintext message to encrypt
81+
* @param msg_len Length of the message
82+
* @param ciphertext_out Output buffer for encrypted data
83+
* @return Length of the encrypted data or an error code on failure
84+
*/
85+
int csp_crypto_encrypt(uint8_t * msg_begin, uint8_t msg_len, uint8_t * ciphertext_out);
86+
87+
/**
88+
* Get the current system time
89+
*
90+
* @param time Structure to be filled with the current time
91+
*/
3092
void csp_clock_get_time(csp_timestamp_t * time);
93+
94+
/**
95+
* Set the system time
96+
*
97+
* @param time Structure containing the new time to set
98+
* @return 0 on success, -1 on failure
99+
*/
31100
int csp_clock_set_time(const csp_timestamp_t * time);
32101

33102
#ifdef __cplusplus

0 commit comments

Comments
 (0)