Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Grant Ramsay <grant.ramsay@hotmail.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_NET_SSH_COMMON_H_
8#define ZEPHYR_INCLUDE_NET_SSH_COMMON_H_
9
21
22#include <zephyr/kernel.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
29
30struct ssh_transport;
31struct ssh_channel;
32struct ssh_client;
33struct ssh_server;
34
35enum ssh_auth_type {
36 SSH_AUTH_NONE,
37 SSH_AUTH_PASSWORD,
38 SSH_AUTH_PUBKEY
39};
40
41enum ssh_channel_request_type {
42 SSH_CHANNEL_REQUEST_UNKNOWN,
43 SSH_CHANNEL_REQUEST_PSEUDO_TERMINAL,
44 SSH_CHANNEL_REQUEST_X11_FORWARD,
45 SSH_CHANNEL_REQUEST_ENV_VAR,
46 SSH_CHANNEL_REQUEST_SHELL,
47 SSH_CHANNEL_REQUEST_EXEC,
48 SSH_CHANNEL_REQUEST_SUBSYSTEM,
49 SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
50 SSH_CHANNEL_REQUEST_FLOW_CONTROL,
51 SSH_CHANNEL_REQUEST_SIGNAL,
52 SSH_CHANNEL_REQUEST_EXIT_STATUS,
53 SSH_CHANNEL_REQUEST_EXIT_SIGNAL
54};
55
56struct ssh_channel_event {
57 enum ssh_channel_event_type {
58 SSH_CHANNEL_EVENT_OPEN_RESULT, /* Client only */
59 SSH_CHANNEL_EVENT_REQUEST, /* Server only */
60 SSH_CHANNEL_EVENT_REQUEST_RESULT, /* Client only */
61 SSH_CHANNEL_EVENT_RX_DATA_READY,
62 SSH_CHANNEL_EVENT_TX_DATA_READY,
63 SSH_CHANNEL_EVENT_RX_STDERR_DATA_READY,
64 SSH_CHANNEL_EVENT_EOF,
65 SSH_CHANNEL_EVENT_CLOSED
66 } type;
67 union {
68 struct ssh_channel_event_channel_request {
69 enum ssh_channel_request_type type;
70 bool want_reply;
71 /* TODO: Union of request type data */
72 } channel_request;
73 struct ssh_channel_event_channel_request_result {
74 bool success;
75 } channel_request_result;
76 };
77};
78
79typedef int (*ssh_channel_event_callback_t)(struct ssh_channel *channel,
80 const struct ssh_channel_event *event,
81 void *user_data);
82
83struct ssh_transport_event {
84 enum ssh_transport_event_type {
85 SSH_TRANSPORT_EVENT_CLOSED,
86 SSH_TRANSPORT_EVENT_SERVICE_ACCEPTED, /* Client only */
87 SSH_TRANSPORT_EVENT_AUTHENTICATE_RESULT, /* Client only */
88 SSH_TRANSPORT_EVENT_CHANNEL_OPEN, /* Server only */
89 } type;
90 union {
91 struct ssh_transport_event_authenticate_result {
92 bool success;
93 } authenticate_result;
94 struct ssh_transport_event_channel_open {
95 struct ssh_channel *channel;
96 } channel_open;
97 };
98};
99
100typedef int (*ssh_transport_event_callback_t)(struct ssh_transport *transport,
101 const struct ssh_transport_event *event,
102 void *user_data);
103
104#define SSH_EXTENDED_DATA_STDERR 1
105
106#ifdef CONFIG_SSH_CLIENT
107const char *ssh_transport_client_user_name(struct ssh_transport *transport);
108int ssh_transport_auth_password(struct ssh_transport *transport, const char *user_name,
109 const char *password);
110int ssh_transport_channel_open(struct ssh_transport *transport,
111 ssh_channel_event_callback_t callback, void *user_data);
112#endif
113
114#ifdef CONFIG_SSH_SERVER
115int ssh_channel_open_result(struct ssh_channel *channel, bool success,
116 ssh_channel_event_callback_t callback, void *user_data);
117#endif
118int ssh_channel_request_result(struct ssh_channel *channel, bool success);
119
120#ifdef CONFIG_SSH_CLIENT
121int ssh_channel_request_shell(struct ssh_channel *channel);
122#endif
123
124int ssh_channel_read(struct ssh_channel *channel, void *data, uint32_t len);
125int ssh_channel_write(struct ssh_channel *channel, const void *data, uint32_t len);
126int ssh_channel_read_stderr(struct ssh_channel *channel, void *data, uint32_t len);
127int ssh_channel_write_stderr(struct ssh_channel *channel, const void *data, uint32_t len);
128
130
139typedef void (*ssh_service_client_cb_t)(struct ssh_client *ssh,
140 int instance,
141 void *user_data);
142
150
159typedef void (*ssh_service_server_cb_t)(struct ssh_server *sshd,
160 int instance,
161 void *user_data);
162
170
171
172#ifdef __cplusplus
173}
174#endif
175
179
180#endif /* ZEPHYR_INCLUDE_NET_SSH_COMMON_H_ */
void(* ssh_service_client_cb_t)(struct ssh_client *ssh, int instance, void *user_data)
Callback used while iterating over SSH client connections.
Definition common.h:139
void(* ssh_service_server_cb_t)(struct ssh_server *sshd, int instance, void *user_data)
Callback used while iterating over SSH server connections.
Definition common.h:159
void ssh_client_foreach(ssh_service_client_cb_t cb, void *user_data)
Go through all SSH client connections.
void ssh_server_foreach(ssh_service_server_cb_t cb, void *user_data)
Go through all SSH server connections.
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90