Lines Matching +full:frame +full:- +full:buffer

1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * Copyright (C) 2019-2022 Maximilian Luz <luzmaximilian@gmail.com>
18 * struct msgbuf - Buffer struct to construct SSH messages.
19 * @begin: Pointer to the beginning of the allocated buffer space.
20 * @end: Pointer to the end (one past last element) of the allocated buffer
22 * @ptr: Pointer to the first free element in the buffer.
31 * msgb_init() - Initialize the given message buffer struct.
32 * @msgb: The buffer struct to initialize
33 * @ptr: Pointer to the underlying memory by which the buffer will be backed.
36 * Initialize the given message buffer struct using the provided memory as
41 msgb->begin = ptr; in msgb_init()
42 msgb->end = ptr + cap; in msgb_init()
43 msgb->ptr = ptr; in msgb_init()
47 * msgb_bytes_used() - Return the current number of bytes used in the buffer.
48 * @msgb: The message buffer.
52 return msgb->ptr - msgb->begin; in msgb_bytes_used()
57 *msgb->ptr = value; in __msgb_push_u8()
58 msgb->ptr += sizeof(u8); in __msgb_push_u8()
63 put_unaligned_le16(value, msgb->ptr); in __msgb_push_u16()
64 msgb->ptr += sizeof(u16); in __msgb_push_u16()
68 * msgb_push_u16() - Push a u16 value to the buffer.
69 * @msgb: The message buffer.
70 * @value: The value to push to the buffer.
74 if (WARN_ON(msgb->ptr + sizeof(u16) > msgb->end)) in msgb_push_u16()
81 * msgb_push_syn() - Push SSH SYN bytes to the buffer.
82 * @msgb: The message buffer.
90 * msgb_push_buf() - Push raw data to the buffer.
91 * @msgb: The message buffer.
92 * @buf: The data to push to the buffer.
93 * @len: The length of the data to push to the buffer.
97 msgb->ptr = memcpy(msgb->ptr, buf, len) + len; in msgb_push_buf()
101 * msgb_push_crc() - Compute CRC and push it to the buffer.
102 * @msgb: The message buffer.
112 * msgb_push_frame() - Push a SSH message frame header to the buffer.
113 * @msgb: The message buffer
114 * @ty: The type of the frame.
115 * @len: The length of the payload of the frame.
116 * @seq: The sequence ID of the frame/packet.
120 u8 *const begin = msgb->ptr; in msgb_push_frame()
122 if (WARN_ON(msgb->ptr + sizeof(struct ssh_frame) > msgb->end)) in msgb_push_frame()
125 __msgb_push_u8(msgb, ty); /* Frame type. */ in msgb_push_frame()
126 __msgb_push_u16(msgb, len); /* Frame payload length. */ in msgb_push_frame()
127 __msgb_push_u8(msgb, seq); /* Frame sequence ID. */ in msgb_push_frame()
129 msgb_push_crc(msgb, begin, msgb->ptr - begin); in msgb_push_frame()
133 * msgb_push_ack() - Push a SSH ACK frame to the buffer.
134 * @msgb: The message buffer
135 * @seq: The sequence ID of the frame/packet to be ACKed.
142 /* ACK-type frame + CRC. */ in msgb_push_ack()
145 /* Payload CRC (ACK-type frames do not have a payload). */ in msgb_push_ack()
146 msgb_push_crc(msgb, msgb->ptr, 0); in msgb_push_ack()
150 * msgb_push_nak() - Push a SSH NAK frame to the buffer.
151 * @msgb: The message buffer
158 /* NAK-type frame + CRC. */ in msgb_push_nak()
161 /* Payload CRC (ACK-type frames do not have a payload). */ in msgb_push_nak()
162 msgb_push_crc(msgb, msgb->ptr, 0); in msgb_push_nak()
166 * msgb_push_cmd() - Push a SSH command frame with payload to the buffer.
167 * @msgb: The message buffer.
168 * @seq: The sequence ID (SEQ) of the frame/packet.
169 * @rqid: The request ID (RQID) of the request contained in the frame.
170 * @rqst: The request to wrap in the frame.
181 /* Command frame + CRC. */ in msgb_push_cmd()
182 msgb_push_frame(msgb, type, sizeof(struct ssh_command) + rqst->length, seq); in msgb_push_cmd()
184 /* Frame payload: Command struct + payload. */ in msgb_push_cmd()
185 if (WARN_ON(msgb->ptr + sizeof(struct ssh_command) > msgb->end)) in msgb_push_cmd()
188 cmd = msgb->ptr; in msgb_push_cmd()
191 __msgb_push_u8(msgb, rqst->target_category); /* Target category. */ in msgb_push_cmd()
192 __msgb_push_u8(msgb, rqst->target_id); /* Target ID. */ in msgb_push_cmd()
194 __msgb_push_u8(msgb, rqst->instance_id); /* Instance ID. */ in msgb_push_cmd()
196 __msgb_push_u8(msgb, rqst->command_id); /* Command ID. */ in msgb_push_cmd()
199 msgb_push_buf(msgb, rqst->payload, rqst->length); in msgb_push_cmd()
202 msgb_push_crc(msgb, cmd, msgb->ptr - cmd); in msgb_push_cmd()