18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * fs/hmdfs/comm/transport.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef HMDFS_TRANSPORT_H
98c2ecf20Sopenharmony_ci#define HMDFS_TRANSPORT_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "connection.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define ENCRYPT_FLAG 1
148c2ecf20Sopenharmony_ci#define DECRYPT_FLAG 0
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct aeadcrypt_result {
178c2ecf20Sopenharmony_ci	struct completion completion;
188c2ecf20Sopenharmony_ci	int err;
198c2ecf20Sopenharmony_ci};
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define ADAPTER_MESSAGE_LENGTH (1024 * 1024 + 1024) // 1M + 1K
228c2ecf20Sopenharmony_ci#define MAX_RECV_SIZE sizeof(struct hmdfs_head_cmd)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define TCP_KVEC_HEAD 0
258c2ecf20Sopenharmony_ci#define TCP_KVEC_DATA 1
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cienum TCP_KVEC_FILE_ELE_INDEX {
288c2ecf20Sopenharmony_ci	TCP_KVEC_FILE_PARA = 1,
298c2ecf20Sopenharmony_ci	TCP_KVEC_FILE_CONTENT = 2,
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cienum TCP_KVEC_TYPE {
338c2ecf20Sopenharmony_ci	TCP_KVEC_ELE_SINGLE = 1,
348c2ecf20Sopenharmony_ci	TCP_KVEC_ELE_DOUBLE = 2,
358c2ecf20Sopenharmony_ci	TCP_KVEC_ELE_TRIPLE = 3,
368c2ecf20Sopenharmony_ci};
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define TCP_RECV_TIMEOUT     2
398c2ecf20Sopenharmony_ci#define MAX_RECV_RETRY_TIMES 2
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#ifndef SO_RCVTIMEO
428c2ecf20Sopenharmony_ci#define SO_RCVTIMEO SO_RCVTIMEO_OLD
438c2ecf20Sopenharmony_ci#endif
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistruct tcp_handle {
468c2ecf20Sopenharmony_ci	struct connection *connect;
478c2ecf20Sopenharmony_ci	int recvbuf_maxsize;
488c2ecf20Sopenharmony_ci	struct mutex close_mutex;
498c2ecf20Sopenharmony_ci	/*
508c2ecf20Sopenharmony_ci	 * To achieve atomicity.
518c2ecf20Sopenharmony_ci	 *
528c2ecf20Sopenharmony_ci	 * The sock lock held at the tcp layer may be temporally released at
538c2ecf20Sopenharmony_ci	 * `sk_wait_event()` when waiting for sock buffer. From this point on,
548c2ecf20Sopenharmony_ci	 * threads serialized at the initial call to `lock_sock()` contained
558c2ecf20Sopenharmony_ci	 * in `tcp_sendmsg()` can proceed, resuling in intermixed messages.
568c2ecf20Sopenharmony_ci	 */
578c2ecf20Sopenharmony_ci	struct mutex send_mutex;
588c2ecf20Sopenharmony_ci	struct socket *sock;
598c2ecf20Sopenharmony_ci	int fd;
608c2ecf20Sopenharmony_ci	struct kmem_cache *recv_cache;
618c2ecf20Sopenharmony_ci	struct task_struct *recv_task;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_civoid hmdfs_get_connection(struct hmdfs_peer *peer);
658c2ecf20Sopenharmony_civoid hmdfs_reget_connection(struct connection *conn);
668c2ecf20Sopenharmony_cistruct connection *hmdfs_get_conn_tcp(struct hmdfs_peer *node, int socket_fd,
678c2ecf20Sopenharmony_ci				      uint8_t *master_key, uint8_t status);
688c2ecf20Sopenharmony_civoid tcp_stop_connect(struct connection *connect);
698c2ecf20Sopenharmony_ciuint32_t hmdfs_tcpi_rtt(struct hmdfs_peer *node);
708c2ecf20Sopenharmony_civoid tcp_close_socket(struct tcp_handle *tcp);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#ifdef CONFIG_HMDFS_FS_ENCRYPTION
738c2ecf20Sopenharmony_ciint tcp_send_rekey_request(struct connection *connect);
748c2ecf20Sopenharmony_ci#endif
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#endif
77