|
1 | 1 | /****************************************************************************
|
2 | 2 | * **File:** csp/csp_hooks.h
|
3 | 3 | *
|
4 |
| - * **Description:** See Hooks in CSP |
| 4 | + * **Description:** Hooks that can be implemented in CSP, see Hooks in csp for more information |
5 | 5 | ****************************************************************************/
|
6 | 6 | #pragma once
|
7 | 7 |
|
|
12 | 12 | extern "C" {
|
13 | 13 | #endif
|
14 | 14 |
|
| 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 | + */ |
15 | 24 | 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 | + */ |
16 | 32 | void csp_input_hook(csp_iface_t * iface, csp_packet_t * packet);
|
17 | 33 |
|
| 34 | +/** |
| 35 | + * Hook called for system reboot |
| 36 | + */ |
18 | 37 | void csp_reboot_hook(void);
|
| 38 | + |
| 39 | +/** |
| 40 | + * Hook called for system shutdown |
| 41 | + */ |
19 | 42 | void csp_shutdown_hook(void);
|
20 | 43 |
|
| 44 | +/** |
| 45 | + * Returns the available free memory |
| 46 | + * @return Free memory in bytes |
| 47 | + */ |
21 | 48 | 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 | + */ |
22 | 56 | unsigned int csp_ps_hook(csp_packet_t * packet);
|
23 | 57 |
|
| 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 | + */ |
24 | 65 | void csp_panic(const char * msg);
|
25 | 66 |
|
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); |
29 | 76 |
|
| 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 | + */ |
30 | 92 | 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 | + */ |
31 | 100 | int csp_clock_set_time(const csp_timestamp_t * time);
|
32 | 101 |
|
33 | 102 | #ifdef __cplusplus
|
|
0 commit comments