xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*******************************************************************************
|
| 2 | * Include header files *
|
| 3 | ******************************************************************************/
|
| 4 | #include <linux/module.h>
|
| 5 | #include <net/sock.h>
|
| 6 | #include <net/af_unix.h>
|
| 7 | #include <linux/syscalls.h>
|
| 8 | #include <linux/file.h>
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 9 | #include <linux/debugfs.h>
|
| 10 | #include <linux/seq_file.h>
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 11 | //#include "ram_config.h"
|
| 12 | #include <linux/socket_rpmsg.h>
|
| 13 |
|
| 14 | #define SOCK_DATA_ALIGN(X) ALIGN(X, SMP_CACHE_BYTES)
|
| 15 | #define SOCK_DATA_MAX_LEN 8*1024
|
| 16 | #define ICP_CHN_SOCKET 32
|
| 17 | #define sock_init_sema sema_init
|
| 18 | #define sock_get_sema down_interruptible
|
| 19 | #define sock_put_sema up
|
| 20 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 21 | extern int socket_rpmsg_enable;
|
| 22 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 23 | struct sock_channel g_sock_chn_info;
|
| 24 | struct sock_rpmsg g_sock_rpmsg;
|
| 25 | struct ipc_socket *g_socket_ipc;
|
| 26 |
|
| 27 | struct semaphore g_sock_sem;
|
| 28 | unsigned int g_sock_timeout = 5*1000;
|
| 29 | //´æ·ÅÁ´Â·ÐÅÏ¢£¬Ò»¶Ësocket¹Ø±Õ£¬ÆäËùÓйØÁªµÄsocket¾ùɾ³ý£¬Á´Â·ÐÅÏ¢Öдæ·Å5Ôª×飨¿Í»§¶Ë¡¢·þÎñ¶Ë¡¢ºÍ´úÀí£©
|
| 30 | struct hlist_head g_ipc_sockets;
|
| 31 | struct hlist_head g_sock_rpmsg_info;
|
| 32 | struct hlist_head g_sockets_info;
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 33 | struct hlist_head g_sunaddr_info;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 34 | char* flag_value[] ={
|
| 35 | "SOCK_DEAD",
|
| 36 | "SOCK_DONE",
|
| 37 | "SOCK_URGINLINE",
|
| 38 | "SOCK_KEEPOPEN",
|
| 39 | "SOCK_LINGER",
|
| 40 | "SOCK_DESTROY",
|
| 41 | "SOCK_BROADCAST",
|
| 42 | "SOCK_TIMESTAMP",
|
| 43 | "SOCK_ZAPPED",
|
| 44 | "SOCK_USE_WRITE_QUEUE", /* whether to call sk->sk_write_space in sock_wfree */
|
| 45 | "SOCK_DBG", /* %SO_DEBUG setting */
|
| 46 | "SOCK_RCVTSTAMP", /* %SO_TIMESTAMP setting */
|
| 47 | "SOCK_RCVTSTAMPNS", /* %SO_TIMESTAMPNS setting */
|
| 48 | "SOCK_LOCALROUTE", /* route locally only, %SO_DONTROUTE setting */
|
| 49 | "SOCK_QUEUE_SHRUNK", /* write queue has been shrunk recently */
|
| 50 | "SOCK_TIMESTAMPING_TX_HARDWARE", /* %SOF_TIMESTAMPING_TX_HARDWARE */
|
| 51 | "SOCK_TIMESTAMPING_TX_SOFTWARE", /* %SOF_TIMESTAMPING_TX_SOFTWARE */
|
| 52 | "SOCK_TIMESTAMPING_RX_HARDWARE", /* %SOF_TIMESTAMPING_RX_HARDWARE */
|
| 53 | "SOCK_TIMESTAMPING_RX_SOFTWARE", /* %SOF_TIMESTAMPING_RX_SOFTWARE */
|
| 54 | "SOCK_TIMESTAMPING_SOFTWARE", /* %SOF_TIMESTAMPING_SOFTWARE */
|
| 55 | "SOCK_TIMESTAMPING_RAW_HARDWARE", /* %SOF_TIMESTAMPING_RAW_HARDWARE */
|
| 56 | "SOCK_TIMESTAMPING_SYS_HARDWARE", /* %SOF_TIMESTAMPING_SYS_HARDWARE */
|
| 57 | "SOCK_FASYNC", /* fasync() active */
|
| 58 | "SOCK_RXQ_OVFL",
|
| 59 | "SOCK_ZEROCOPY", /* buffers from userspace */
|
| 60 | "SOCK_WIFI_STATUS", /* push wifi status to userspace */
|
| 61 | "SOCK_NOFCS",
|
| 62 | "SOCK_IPCSOCK"
|
| 63 | };
|
| 64 |
|
| 65 | DEFINE_SPINLOCK(sock_table_lock);
|
| 66 | EXPORT_SYMBOL_GPL(sock_table_lock);
|
| 67 |
|
| 68 | DEFINE_SPINLOCK(sock_rpmsg_table_lock);
|
| 69 | EXPORT_SYMBOL_GPL(sock_rpmsg_table_lock);
|
| 70 |
|
| 71 | DEFINE_SPINLOCK(sock_socket_table_lock);
|
| 72 | EXPORT_SYMBOL_GPL(sock_socket_table_lock);
|
| 73 |
|
| 74 | DEFINE_SPINLOCK(sock_release_table_lock);
|
| 75 | EXPORT_SYMBOL_GPL(sock_release_table_lock);
|
| 76 |
|
| 77 | DEFINE_SPINLOCK(sock_release_lock);
|
| 78 | EXPORT_SYMBOL_GPL(sock_release_lock);
|
| 79 |
|
| 80 | DEFINE_SPINLOCK(sock_release_peer_lock);
|
| 81 | EXPORT_SYMBOL_GPL(sock_release_peer_lock);
|
| 82 |
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 83 | DEFINE_SPINLOCK(sock_socketaddr_table_lock);
|
| 84 | EXPORT_SYMBOL_GPL(sock_socketaddr_table_lock);
|
| 85 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 86 | static struct dentry *ipcsocket_debugfs_dir_entry_root;
|
| 87 | static struct dentry *ipcsocket_debugfs_dir_entry_proc;
|
| 88 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 89 | #define unix_peer(sk) (unix_sk(sk)->peer)
|
| 90 |
|
| 91 | extern struct sock *unix_find_other_proxy(struct net *net,
|
| 92 | struct sockaddr_un *sunname, int len,
|
| 93 | int type, unsigned int hash, int *error);
|
| 94 |
|
| 95 | extern int unix_dgram_peer_wake_connect_proxy(struct sock *sk, struct sock *other);
|
| 96 |
|
| 97 | extern void unix_dgram_peer_wake_disconnect_proxy(struct sock *sk, struct sock *other);
|
| 98 |
|
| 99 | extern void unix_dgram_peer_wake_disconnect_wakeup_proxy(struct sock *sk,
|
| 100 | struct sock *other);
|
| 101 | extern long unix_wait_for_peer_proxy(struct sock *other, long timeo);
|
| 102 | extern int unix_recvq_full_proxy(const struct sock *sk);
|
| 103 | extern int unix_recvq_full_proxy_lockless_and_deadstate(const struct sock *other);
|
| 104 | extern int unix_stream_connect_proxy(struct socket *sock, struct sockaddr *uaddr,
|
| 105 | int addr_len, int flags);
|
| 106 | extern void unix_dgram_disconnected_proxy(struct sock *sk, struct sock *other);
|
| 107 | extern int unix_mkname_proxy(struct sockaddr_un *sunaddr, int len, unsigned *hashp);
|
| 108 | extern void unix_release_sock_proxy(struct sock *sk);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 109 | extern void init_peercred_proxy(struct sock *sk);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 110 |
|
| 111 | //static void delayed_release(struct work_struct *unused);
|
| 112 | int sock_soc_socket_is_valid(struct socket* proxysock, struct socket* localsock);
|
| 113 | int sock_soc_release_peer(struct release_socket* rsock);
|
| 114 |
|
| 115 | static LIST_HEAD(delayed_release_list);
|
| 116 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 117 | #define DEFINE_SHOW_ATTRIBUTE(__name) \
|
| 118 | static int __name##_open(struct inode *inode, struct file *file) \
|
| 119 | { \
|
| 120 | return single_open(file, __name##_show, inode->i_private); \
|
| 121 | } \
|
| 122 | \
|
| 123 | static const struct file_operations __name##_fops = { \
|
| 124 | .owner = THIS_MODULE, \
|
| 125 | .open = __name##_open, \
|
| 126 | .read = seq_read, \
|
| 127 | .llseek = seq_lseek, \
|
| 128 | .release = single_release, \
|
| 129 | }
|
| 130 |
|
| 131 | static int ipc_socket_info_show(struct seq_file *m, void *unused);
|
| 132 | DEFINE_SHOW_ATTRIBUTE(ipc_socket_info);
|
| 133 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 134 | enum sock_flags_cap {
|
| 135 | SOCK_DEAD_CAP,
|
| 136 | SOCK_DONE_CAP,
|
| 137 | SOCK_URGINLINE_CAP,
|
| 138 | SOCK_KEEPOPEN_CAP,
|
| 139 | SOCK_LINGER_CAP,
|
| 140 | SOCK_DESTROY_CAP,
|
| 141 | SOCK_BROADCAST_CAP,
|
| 142 | SOCK_TIMESTAMP_CAP,
|
| 143 | SOCK_ZAPPED_CAP,
|
| 144 | SOCK_USE_WRITE_QUEUE_CAP, /* whether to call sk->sk_write_space in sock_wfree */
|
| 145 | SOCK_DBG_CAP, /* %SO_DEBUG setting */
|
| 146 | SOCK_RCVTSTAMP_CAP, /* %SO_TIMESTAMP setting */
|
| 147 | SOCK_RCVTSTAMPNS_CAP, /* %SO_TIMESTAMPNS setting */
|
| 148 | SOCK_LOCALROUTE_CAP, /* route locally only, %SO_DONTROUTE setting */
|
| 149 | SOCK_MEMALLOC_CAP, /* VM depends on this socket for swapping */
|
| 150 | SOCK_TIMESTAMPING_RX_SOFTWARE_CAP, /* %SOF_TIMESTAMPING_RX_SOFTWARE */
|
| 151 | SOCK_FASYNC_CAP, /* fasync() active */
|
| 152 | SOCK_RXQ_OVFL_CAP,
|
| 153 | SOCK_ZEROCOPY_CAP, /* buffers from userspace */
|
| 154 | SOCK_WIFI_STATUS_CAP, /* push wifi status to userspace */
|
| 155 | SOCK_NOFCS_CAP, /* Tell NIC not to do the Ethernet FCS.
|
| 156 | * Will use last 4 bytes of packet sent from
|
| 157 | * user-space instead.
|
| 158 | */
|
| 159 | SOCK_FILTER_LOCKED_CAP, /* Filter cannot be changed anymore */
|
| 160 | SOCK_SELECT_ERR_QUEUE_CAP, /* Wake select on error queue */
|
| 161 | SOCK_RCU_FREE_CAP, /* wait rcu grace period in sk_destruct() */
|
| 162 | SOCK_TXTIME_CAP,
|
| 163 | SOCK_XDP_CAP, /* XDP is attached */
|
| 164 | SOCK_TSTAMP_NEW_CAP, /* Indicates 64 bit timestamps always */
|
| 165 |
|
| 166 | SOCK_IPCSOCK_CAP, /*Indicates whether it is a cross core socket */
|
| 167 |
|
| 168 | };
|
| 169 |
|
| 170 |
|
| 171 | enum sock_flags_cap convert_to_cap_sock_flag(enum sock_flags flag)
|
| 172 | {
|
| 173 | switch(flag){
|
| 174 | case SOCK_DEAD:
|
| 175 | return SOCK_DEAD_CAP;
|
| 176 | case SOCK_DONE:
|
| 177 | return SOCK_DONE_CAP;
|
| 178 | case SOCK_URGINLINE:
|
| 179 | return SOCK_URGINLINE_CAP;
|
| 180 | case SOCK_KEEPOPEN:
|
| 181 | return SOCK_KEEPOPEN_CAP;
|
| 182 | case SOCK_LINGER:
|
| 183 | return SOCK_LINGER_CAP;
|
| 184 | case SOCK_DESTROY:
|
| 185 | return SOCK_DESTROY_CAP;
|
| 186 | case SOCK_BROADCAST:
|
| 187 | return SOCK_BROADCAST_CAP;
|
| 188 | case SOCK_TIMESTAMP:
|
| 189 | return SOCK_TIMESTAMP_CAP;
|
| 190 | case SOCK_ZAPPED:
|
| 191 | return SOCK_ZAPPED_CAP;
|
| 192 | case SOCK_USE_WRITE_QUEUE:
|
| 193 | return SOCK_USE_WRITE_QUEUE_CAP;
|
| 194 | case SOCK_DBG:
|
| 195 | return SOCK_DBG_CAP;
|
| 196 | case SOCK_RCVTSTAMP:
|
| 197 | return SOCK_RCVTSTAMP_CAP;
|
| 198 | case SOCK_RCVTSTAMPNS:
|
| 199 | return SOCK_RCVTSTAMPNS_CAP;
|
| 200 | case SOCK_LOCALROUTE:
|
| 201 | return SOCK_LOCALROUTE_CAP;
|
| 202 | case SOCK_QUEUE_SHRUNK:
|
| 203 | return -1;
|
| 204 | case SOCK_TIMESTAMPING_TX_HARDWARE:
|
| 205 | return -1;
|
| 206 | case SOCK_TIMESTAMPING_TX_SOFTWARE:
|
| 207 | return -1;
|
| 208 | case SOCK_TIMESTAMPING_RX_HARDWARE:
|
| 209 | return -1;
|
| 210 | case SOCK_TIMESTAMPING_RX_SOFTWARE:
|
| 211 | return SOCK_TIMESTAMPING_RX_SOFTWARE_CAP;
|
| 212 | case SOCK_TIMESTAMPING_SOFTWARE:
|
| 213 | return -1;
|
| 214 | case SOCK_TIMESTAMPING_RAW_HARDWARE:
|
| 215 | return -1;
|
| 216 | case SOCK_TIMESTAMPING_SYS_HARDWARE:
|
| 217 | return -1;
|
| 218 | case SOCK_FASYNC:
|
| 219 | return SOCK_FASYNC_CAP;
|
| 220 | case SOCK_RXQ_OVFL:
|
| 221 | return SOCK_RXQ_OVFL_CAP;
|
| 222 | case SOCK_ZEROCOPY:
|
| 223 | return SOCK_ZEROCOPY_CAP;
|
| 224 | case SOCK_WIFI_STATUS:
|
| 225 | return SOCK_WIFI_STATUS_CAP;
|
| 226 | case SOCK_NOFCS:
|
| 227 | return SOCK_NOFCS_CAP;
|
| 228 | default:
|
| 229 | return -1;
|
| 230 | }
|
| 231 | }
|
| 232 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 233 | static int ipc_socket_info_show(struct seq_file *m, void *unused)
|
| 234 | {
|
| 235 | struct task_struct *task = NULL;
|
| 236 | char taskname[TASK_COMM_LEN] = {0};
|
| 237 | struct ipc_socket *p;
|
| 238 | struct hlist_node *pos,*n;
|
| 239 | struct socket* localsocket;
|
| 240 |
|
| 241 | spin_lock(&sock_table_lock);
|
| 242 | if(hlist_empty(&g_ipc_sockets))
|
| 243 | {
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 244 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 245 | sk_soc_warn("sock_print_ipc_socket_info g_ipc_sockets is empty");
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 246 | return 0;
|
| 247 | }
|
| 248 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 249 | memset(taskname, 0, TASK_COMM_LEN);
|
| 250 | localsocket = p->localsocket;
|
| 251 | task = localsocket->task;
|
| 252 | get_task_comm(taskname, task);
|
| 253 | sk_soc_warn("pid=%d, taskname=%s", task->pid, taskname);
|
| 254 | }
|
| 255 | spin_unlock(&sock_table_lock);
|
| 256 | return 0;
|
| 257 | }
|
| 258 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 259 | static int sock_soc_is_socket_peer(struct socket* socket, struct socket* peer)
|
| 260 | {
|
| 261 | struct socket_info *p;
|
| 262 | struct hlist_node *n, *pos;
|
| 263 | spin_lock(&sock_release_peer_lock);
|
| 264 | hlist_for_each_entry_safe(p, pos, n, &socket->peer, hlist_node) {
|
| 265 | if(p->proxysocket == peer){
|
| 266 | spin_unlock(&sock_release_peer_lock);
|
| 267 | return 0;
|
| 268 | }
|
| 269 | }
|
| 270 | spin_unlock(&sock_release_peer_lock);
|
| 271 | return -1;
|
| 272 | }
|
| 273 |
|
| 274 | static inline void sock_soc_insert_socket_peer(struct socket* socket, struct socket* peer)
|
| 275 | {
|
| 276 | struct socket_info *psock_socket_info = NULL;
|
| 277 |
|
| 278 | //ÏȲ鿴peerÊÇ·ñÒѾÔÚsocketµÄpeer_listÖÐ
|
| 279 | if(0 == sock_soc_is_socket_peer(socket, peer)){
|
| 280 | sk_soc_info("sock_soc_insert_socket_peer, peer already exist");
|
| 281 | return;
|
| 282 | }
|
| 283 | psock_socket_info = (struct socket_info *)kzalloc(sizeof(struct socket_info), GFP_ATOMIC);
|
| 284 | if(psock_socket_info == NULL){
|
| 285 | return;
|
| 286 | }
|
| 287 | memset(psock_socket_info, 0, sizeof(struct socket_info));
|
| 288 | psock_socket_info->proxysocket = peer;
|
| 289 | psock_socket_info->localsocket = socket;
|
| 290 |
|
| 291 | sk_soc_info("sock_soc_insert_socket_peer sucess, proxysocket=%x, localsock=%x", psock_socket_info->proxysocket, psock_socket_info->localsocket);
|
| 292 |
|
| 293 | spin_lock(&sock_release_peer_lock);
|
| 294 | INIT_HLIST_NODE(&psock_socket_info->hlist_node);
|
| 295 | hlist_add_head(&psock_socket_info->hlist_node, &socket->peer);
|
| 296 | spin_unlock(&sock_release_peer_lock);
|
| 297 | }
|
| 298 |
|
| 299 | static int sock_soc_del_socket_peer(struct socket* socket, struct socket* peer)
|
| 300 | {
|
| 301 | struct socket_info *p;
|
| 302 | struct hlist_node *n, *pos;
|
| 303 | spin_lock(&sock_release_peer_lock);
|
| 304 | hlist_for_each_entry_safe(p, pos, n, &socket->peer, hlist_node) {
|
| 305 | if(p->proxysocket == peer){
|
| 306 | hlist_del(&p->hlist_node);
|
| 307 | spin_unlock(&sock_release_peer_lock);
|
| 308 | kfree(p);
|
| 309 | return 0;
|
| 310 | }
|
| 311 | }
|
| 312 | spin_unlock(&sock_release_peer_lock);
|
| 313 | return -1;
|
| 314 | }
|
| 315 |
|
| 316 | static inline void sock_soc_insert_socket(struct hlist_node *list_node)
|
| 317 | {
|
| 318 | spin_lock(&sock_table_lock);
|
| 319 | hlist_add_head(list_node, &g_ipc_sockets);
|
| 320 | spin_unlock(&sock_table_lock);
|
| 321 | }
|
| 322 |
|
| 323 | //ÓÃÓÚÅжϱ¾µØsocketÊÇ·ñÔÚipcÁбíÖУ¬¿ÉÄÜ´æÔÚ¶àÌõ¼Ç¼
|
| 324 | static struct ipc_socket *sock_soc_get_ipcsocket_by_localsocket(struct socket *localsocket)
|
| 325 | {
|
| 326 | struct ipc_socket *p;
|
| 327 | struct hlist_node *pos,*n;
|
| 328 | spin_lock(&sock_table_lock);
|
| 329 | if(hlist_empty(&g_ipc_sockets))
|
| 330 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 331 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 332 | sk_soc_info("sock_soc_get_ipcsocket_by_proxysock g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 333 | return NULL;
|
| 334 | }
|
| 335 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 336 | if(p->localsocket == localsocket){
|
| 337 | spin_unlock(&sock_table_lock);
|
| 338 | return p;
|
| 339 | }
|
| 340 | }
|
| 341 | spin_unlock(&sock_table_lock);
|
| 342 | return NULL;
|
| 343 | }
|
| 344 |
|
| 345 | //´Ë´¦µÄsockΪ´úÀísocket¶ÔÓ¦µÄsock£¬ÒòΪÿ¸ö´úÀísocketÔÚg_ipc_sockets±íÖÐÊÇΨһµÄ
|
| 346 | static struct ipc_socket *sock_soc_get_ipcsocket_by_proxysock(struct sock *s)
|
| 347 | {
|
| 348 | struct ipc_socket *p;
|
| 349 | struct hlist_node *pos,*n;
|
| 350 | spin_lock(&sock_table_lock);
|
| 351 | if(hlist_empty(&g_ipc_sockets))
|
| 352 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 353 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 354 | sk_soc_info("sock_soc_get_ipcsocket_by_proxysock g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 355 | return NULL;
|
| 356 | }
|
| 357 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 358 | if(p->sock == s){
|
| 359 | spin_unlock(&sock_table_lock);
|
| 360 | return p;
|
| 361 | }
|
| 362 | }
|
| 363 | spin_unlock(&sock_table_lock);
|
| 364 | return NULL;
|
| 365 | }
|
| 366 |
|
| 367 | //¸ù¾Ý¿Í»§¶ËsocketºÍ·þÎñ¶Ësocket²éÕÒ¶ÔÓ¦µÄipc_socket
|
| 368 | static struct ipc_socket *sock_get_ipcsocket_by_local_and_remote(void* localsock, void* remotesock)
|
| 369 | {
|
| 370 | struct ipc_socket *p;
|
| 371 | struct hlist_node *pos,*n;
|
| 372 | spin_lock(&sock_table_lock);
|
| 373 | if(hlist_empty(&g_ipc_sockets))
|
| 374 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 375 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 376 | sk_soc_info("sock_get_ipcsocket_by_local_and_remote g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 377 | return NULL;
|
| 378 | }
|
| 379 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 380 | if((p->localsocket == localsock)&&(p->remotesocket == remotesock)){
|
| 381 | spin_unlock(&sock_table_lock);
|
| 382 | return p;
|
| 383 | }
|
| 384 | }
|
| 385 | spin_unlock(&sock_table_lock);
|
| 386 | return NULL;
|
| 387 | }
|
| 388 |
|
| 389 | int sock_del_ipc_socket_by_proxysocket(struct socket* socket)
|
| 390 | {
|
| 391 | struct ipc_socket *p;
|
| 392 | struct hlist_node *pos, *n;
|
| 393 | spin_lock(&sock_table_lock);
|
| 394 | if(hlist_empty(&g_ipc_sockets))
|
| 395 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 396 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 397 | sk_soc_info("sock_del_ipc_socket_by_proxysocket g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 398 | return -1;
|
| 399 | }
|
| 400 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 401 | if(p->socket == socket){
|
| 402 | hlist_del(&p->hlist_node);
|
| 403 | spin_unlock(&sock_table_lock);
|
| 404 | kfree(p);
|
| 405 | return 0;
|
| 406 | }
|
| 407 | }
|
| 408 | spin_unlock(&sock_table_lock);
|
| 409 | return -1;
|
| 410 | }
|
| 411 |
|
| 412 | //ĿǰÏȸù¾Ý¿Í»§¶Ësocket¡¢±¾¶Ë´úÀísocketºÍ·þÎñ¶Ësocket½øÐÐÆ¥Åä
|
| 413 | int sock_is_valide_ipc_socket(struct socket* localsocket, struct socket* proxysocket, struct socket* remotesocket/*, struct socket* remoteproxysocket*/)
|
| 414 | {
|
| 415 | struct ipc_socket *p;
|
| 416 | struct hlist_node *pos, *n;
|
| 417 | spin_lock(&sock_table_lock);
|
| 418 | if(hlist_empty(&g_ipc_sockets))
|
| 419 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 420 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 421 | sk_soc_info("sock_is_valide_ipc_socket g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 422 | return -1;
|
| 423 | }
|
| 424 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 425 | if((p->localsocket == localsocket)&&(p->proxysocket == proxysocket)&&(p->remotesocket == remotesocket)/*&&(p->remoteproxysocket == remoteproxysocket)*/){
|
| 426 |
|
| 427 | spin_unlock(&sock_table_lock);
|
| 428 |
|
| 429 | return 0;
|
| 430 | }
|
| 431 | }
|
| 432 | spin_unlock(&sock_table_lock);
|
| 433 | sk_soc_info("sock_is_valide_ipc_socket failed, localsocket=%x, proxysocket=%x, remotesocket=%x", localsocket, proxysocket, remotesocket);
|
| 434 | return -1;
|
| 435 | }
|
| 436 |
|
| 437 | struct socket *sock_get_local_socket(int fd, int *err)
|
| 438 | {
|
| 439 | struct socket* sock;
|
| 440 | sock = sockfd_lookup(fd, err);
|
| 441 | if(NULL == sock){
|
| 442 | return NULL;
|
| 443 | }
|
| 444 | sockfd_put(sock);
|
| 445 | sk_soc_info("sock_get_local_socket fd=%d, file->f_count=%d ", fd, sock->file->f_count);
|
| 446 | return sock;
|
| 447 | }
|
| 448 |
|
| 449 | static inline void sock_soc_insert_rpmsg_info(struct hlist_node *list_node)
|
| 450 | {
|
| 451 | spin_lock(&sock_rpmsg_table_lock);
|
| 452 | hlist_add_head(list_node, &g_sock_rpmsg_info);
|
| 453 | spin_unlock(&sock_rpmsg_table_lock);
|
| 454 | }
|
| 455 |
|
| 456 | struct sock_rpmsg_info * sock_soc_create_rpmsg_info(void* key)
|
| 457 | {
|
| 458 | struct sock_rpmsg_info *psock_sock_rpmsg_info = NULL;
|
| 459 |
|
| 460 | psock_sock_rpmsg_info = (struct sock_rpmsg_info *)kzalloc(sizeof(struct sock_rpmsg_info), GFP_ATOMIC);
|
| 461 | if(psock_sock_rpmsg_info == NULL){
|
| 462 | sk_soc_info("sock_soc_create_rpmsg_info kzalloc failed \n");
|
| 463 | return NULL;
|
| 464 | }
|
| 465 | memset(psock_sock_rpmsg_info, 0, sizeof(struct sock_rpmsg_info));
|
| 466 | psock_sock_rpmsg_info->key = key;
|
| 467 | sema_init(&psock_sock_rpmsg_info->sock_sem, 0);
|
| 468 | sk_soc_info("sock_soc_create_rpmsg_info sucess, key=%x", key);
|
| 469 | sock_soc_insert_rpmsg_info(&psock_sock_rpmsg_info->hlist_node);
|
| 470 | return psock_sock_rpmsg_info;
|
| 471 | }
|
| 472 |
|
| 473 | struct sock_rpmsg_info * sock_soc_get_rpmsg_info(void* key)
|
| 474 | {
|
| 475 | struct sock_rpmsg_info *p;
|
| 476 | struct hlist_node *pos,*n;
|
| 477 | //sk_soc_info("sock_soc_get_rpmsg_info key=%x \n", key);
|
| 478 | spin_lock(&sock_rpmsg_table_lock);
|
| 479 | hlist_for_each_entry_safe(p, pos, n, &g_sock_rpmsg_info, hlist_node) {
|
| 480 | if(p->key == key){
|
| 481 | spin_unlock(&sock_rpmsg_table_lock);
|
| 482 | return p;
|
| 483 | }
|
| 484 | }
|
| 485 | spin_unlock(&sock_rpmsg_table_lock);
|
| 486 | return NULL;
|
| 487 | }
|
| 488 |
|
| 489 | struct sock_rpmsg_info * sock_soc_del_rpmsg_info(void* key)
|
| 490 | {
|
| 491 | struct sock_rpmsg_info *p;
|
| 492 | struct hlist_node *pos,*n;
|
| 493 | //sk_soc_info("sock_soc_del_rpmsg_info key=%x \n", key);
|
| 494 | spin_lock(&sock_rpmsg_table_lock);
|
| 495 | hlist_for_each_entry_safe(p, pos, n, &g_sock_rpmsg_info, hlist_node) {
|
| 496 | if(p->key == key){
|
| 497 | hlist_del(&p->hlist_node);
|
| 498 | spin_unlock(&sock_rpmsg_table_lock);
|
| 499 | sk_soc_info("sock_soc_del_rpmsg_info sucess, key=%x \n", key);
|
| 500 | kfree(p);
|
| 501 | return 0;
|
| 502 | }
|
| 503 | }
|
| 504 | spin_unlock(&sock_rpmsg_table_lock);
|
| 505 | sk_soc_info("sock_soc_del_rpmsg_info failed, key=%x \n", key);
|
| 506 | return -1;
|
| 507 | }
|
| 508 |
|
| 509 | static inline void sock_soc_insert_socket_info(struct hlist_node *list_node)
|
| 510 | {
|
| 511 | spin_lock(&sock_socket_table_lock);
|
| 512 | hlist_add_head(list_node, &g_sockets_info);
|
| 513 | spin_unlock(&sock_socket_table_lock);
|
| 514 | }
|
| 515 |
|
| 516 | struct socket_info * sock_soc_set_socket_info(struct socket* proxysock, struct socket* localsock)
|
| 517 | {
|
| 518 | struct socket_info *psock_socket_info = NULL;
|
| 519 |
|
| 520 | if(0 == sock_soc_socket_is_valid(proxysock, localsock)){
|
| 521 | sk_soc_info("sock_soc_socket_is_valid is true , do not add again");
|
| 522 | return NULL;
|
| 523 | }
|
| 524 | psock_socket_info = (struct socket_info *)kzalloc(sizeof(struct socket_info), GFP_ATOMIC);
|
| 525 | if(psock_socket_info == NULL){
|
| 526 | return NULL;
|
| 527 | }
|
| 528 | memset(psock_socket_info, 0, sizeof(struct socket_info));
|
| 529 | psock_socket_info->proxysocket = proxysock;
|
| 530 | psock_socket_info->localsocket = localsock;
|
| 531 | //sk_soc_info("sock_soc_set_socket_info sucess, key=%x", sock);
|
| 532 | sock_soc_insert_socket_info(&psock_socket_info->hlist_node);
|
| 533 | sk_soc_info("sock_soc_set_socket_info sucess, proxysocket=%x, localsock=%x", psock_socket_info->proxysocket, psock_socket_info->localsocket);
|
| 534 | return psock_socket_info;
|
| 535 | }
|
| 536 |
|
| 537 | int sock_soc_socket_is_valid(struct socket* proxysock, struct socket* localsock)
|
| 538 | {
|
| 539 | struct ipc_socket *p;
|
| 540 | struct hlist_node *pos,*n;
|
| 541 | spin_lock(&sock_table_lock);
|
| 542 | if(hlist_empty(&g_ipc_sockets))
|
| 543 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 544 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 545 | sk_soc_info("sock_soc_socket_is_valid g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 546 | return -1;
|
| 547 | }
|
| 548 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 549 | if((p->proxysocket == proxysock)&&(p->localsocket == localsock)){
|
| 550 | spin_unlock(&sock_table_lock);
|
| 551 | return 0;
|
| 552 | }
|
| 553 | }
|
| 554 | spin_unlock(&sock_table_lock);
|
| 555 | return -1;
|
| 556 | }
|
| 557 |
|
| 558 | int sock_soc_del_socket_info(struct socket* proxysock, struct socket* localsock)
|
| 559 | {
|
| 560 | struct ipc_socket *p;
|
| 561 | struct hlist_node *pos,*n;
|
| 562 | //sk_soc_info("sock_soc_del_socket_info key=%x \n", sock);
|
| 563 | spin_lock(&sock_table_lock);
|
| 564 | if(hlist_empty(&g_ipc_sockets))
|
| 565 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 566 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 567 | sk_soc_info("sock_soc_del_socket_info g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 568 | return -1;
|
| 569 | }
|
| 570 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 571 | if((p->proxysocket == proxysock)&&(p->localsocket == localsock)){
|
| 572 | hlist_del(&p->hlist_node);
|
| 573 | spin_unlock(&sock_table_lock);
|
| 574 | sk_soc_info("sock_soc_del_socket_info sucess, proxysock=%x, localsock=%x \n", proxysock, localsock);
|
| 575 | kfree(p);
|
| 576 | return 0;
|
| 577 | }
|
| 578 | }
|
| 579 | spin_unlock(&sock_table_lock);
|
| 580 | sk_soc_info("sock_soc_del_socket_info failed, proxysock=%x,localsock=%x \n", proxysock, localsock);
|
| 581 | return -1;
|
| 582 | }
|
| 583 |
|
| 584 | int sock_soc_socket_is_valid_other(struct socket* other)
|
| 585 | {
|
| 586 | return 0;
|
| 587 | }
|
| 588 |
|
| 589 | int sock_soc_socket_is_valid_ipc(struct socket* localsocket, struct socket* remotesocket)
|
| 590 | {
|
| 591 | struct ipc_socket *p;
|
| 592 | struct hlist_node *pos,*n;
|
| 593 | spin_lock(&sock_table_lock);
|
| 594 | if(hlist_empty(&g_ipc_sockets))
|
| 595 | {
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 596 | spin_unlock(&sock_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 597 | sk_soc_info("sock_soc_socket_is_valid_ipc g_ipc_sockets is empty");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 598 | return -1;
|
| 599 | }
|
| 600 | hlist_for_each_entry_safe(p, pos, n, &g_ipc_sockets, hlist_node) {
|
| 601 | if((p->localsocket == localsocket)&&(p->remotesocket == remotesocket)){
|
| 602 | spin_unlock(&sock_table_lock);
|
| 603 | return 0;
|
| 604 | }
|
| 605 | }
|
| 606 | spin_unlock(&sock_table_lock);
|
| 607 | return -1;
|
| 608 | }
|
| 609 |
|
| 610 | struct sock_rpmsg_info * sock_soc_rsp_proc(struct sock_rpmsg* psock_rpmsg)
|
| 611 | {
|
| 612 | struct sock_rpmsg_info *psock_rpmsg_info;
|
| 613 | psock_rpmsg_info = sock_soc_get_rpmsg_info(psock_rpmsg->key);
|
| 614 | if(NULL == psock_rpmsg_info){
|
| 615 | sk_soc_err("sock_soc_get_rpmsg_info failed!");
|
| 616 | return NULL;
|
| 617 | }
|
| 618 | memset(&psock_rpmsg_info->sock_rpmsg, 0, sizeof(struct sock_rpmsg));
|
| 619 | memcpy(&psock_rpmsg_info->sock_rpmsg, psock_rpmsg, sizeof(struct sock_rpmsg));
|
| 620 | up(&psock_rpmsg_info->sock_sem);
|
| 621 | return psock_rpmsg_info;
|
| 622 | }
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 623 |
|
| 624 | bool sock_soc_ipc_sunaddr_exist(struct sockaddr_un *psockaddr_un)
|
| 625 | {
|
| 626 | struct sock_sunaddr_info *p;
|
| 627 | struct hlist_node *pos,*n;
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 628 | spin_lock(&sock_socketaddr_table_lock);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 629 | hlist_for_each_entry_safe(p, pos, n, &g_sunaddr_info, hlist_node) {
|
| 630 | if((p->sockaddr.sun_family == psockaddr_un->sun_family) \
|
| 631 | &&(0 == memcmp(p->sockaddr.sun_path, psockaddr_un->sun_path, UNIX_PATH_MAX))){
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 632 | spin_unlock(&sock_socketaddr_table_lock);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 633 | return true;
|
| 634 | }
|
| 635 | }
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 636 | spin_unlock(&sock_socketaddr_table_lock);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 637 | return false;
|
| 638 | }
|
| 639 |
|
| 640 | static void sock_soc_insert_ipc_sunaddr(struct sockaddr_un *psockaddr_un)
|
| 641 | {
|
| 642 | struct sock_sunaddr_info *psock_sunaddr_info = NULL;
|
| 643 |
|
| 644 | //ÏȲ鿴sunaddrÊÇ·ñÒѾÔÚg_sunaddr_infoÖÐ
|
| 645 | if(true == sock_soc_ipc_sunaddr_exist(psockaddr_un)){
|
| 646 | sk_soc_info("sock_soc_insert_ipc_sunaddr, sunaddr already exist");
|
| 647 | return;
|
| 648 | }
|
| 649 |
|
| 650 | psock_sunaddr_info = (struct sock_sunaddr_info *)kzalloc(sizeof(struct sock_sunaddr_info), GFP_ATOMIC);
|
| 651 | if(psock_sunaddr_info == NULL){
|
| 652 | sk_soc_info("sock_soc_insert_ipc_sunaddr, alloc failed");
|
| 653 | return;
|
| 654 | }
|
| 655 | memset(psock_sunaddr_info, 0, sizeof(struct sock_sunaddr_info));
|
| 656 | memcpy(&psock_sunaddr_info->sockaddr, psockaddr_un, sizeof(struct sockaddr_un));
|
| 657 |
|
| 658 | INIT_HLIST_NODE(&psock_sunaddr_info->hlist_node);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 659 | spin_lock(&sock_socketaddr_table_lock);
|
| 660 | hlist_add_head(&psock_sunaddr_info->hlist_node, &g_sunaddr_info);
|
| 661 | spin_unlock(&sock_socketaddr_table_lock);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 662 | }
|
| 663 |
|
| 664 | static int sock_soc_del_ipc_sunaddr(struct sockaddr_un *psockaddr_un)
|
| 665 | {
|
| 666 | struct sock_sunaddr_info *p;
|
| 667 | struct hlist_node *pos,*n;
|
| 668 | int ret;
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 669 | spin_lock(&sock_socketaddr_table_lock);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 670 | hlist_for_each_entry_safe(p, pos, n, &g_sunaddr_info, hlist_node) {
|
| 671 | if(psockaddr_un->sun_path[0]){
|
| 672 | ret = strncmp(p->sockaddr.sun_path, psockaddr_un->sun_path, strlen(psockaddr_un->sun_path));
|
| 673 | }else{
|
| 674 | ret = strncmp(&p->sockaddr.sun_path[1], &psockaddr_un->sun_path[1], strlen(&psockaddr_un->sun_path[1]));
|
| 675 | }
|
| 676 |
|
| 677 | if((p->sockaddr.sun_family == psockaddr_un->sun_family) && (0 == ret)){
|
| 678 | hlist_del(&p->hlist_node);
|
| 679 | kfree(p);
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 680 | spin_unlock(&sock_socketaddr_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 681 | sk_soc_info("sun_path=%s, del sucess.", psockaddr_un->sun_path);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 682 | return 0;
|
| 683 | }
|
| 684 | }
|
xf.li | e31de8b | 2023-12-26 23:38:58 -0800 | [diff] [blame] | 685 | spin_unlock(&sock_socketaddr_table_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 686 | sk_soc_info("sun_path=%s, del failed", psockaddr_un->sun_path);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 687 | return -1;
|
| 688 | }
|
| 689 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 690 | int unix_is_ipc_socket(struct sock *sock)
|
| 691 | {
|
| 692 | int result;
|
| 693 | result = test_bit(SOCK_IPCSOCK, &sock->sk_flags);
|
| 694 | //sk_soc_info("unix_is_ipc_socket result=%d", result);
|
| 695 | return result;
|
| 696 | }
|
| 697 | EXPORT_SYMBOL_GPL(unix_is_ipc_socket);
|
| 698 |
|
| 699 | int unix_is_ipc_local_socket(struct sock *sock)
|
| 700 | {
|
| 701 | int result;
|
| 702 | result = test_bit(SOCK_IPC_LOCAL, &sock->sk_flags);
|
| 703 | //sk_soc_info("unix_is_ipc_socket result=%d", result);
|
| 704 | return result;
|
| 705 | }
|
| 706 | EXPORT_SYMBOL_GPL(unix_is_ipc_local_socket);
|
| 707 |
|
| 708 | /*·µ»ØÖµ´óÓÚµÈÓÚ0£¬±íʾдͨµÀ³É¹¦£»Ð¡ÓÚ0±íʾдͨµÀʧ°Ü*/
|
| 709 | static int sock_channel_write(struct sock_channel *chninfo, void *buf, unsigned int len)
|
| 710 | {
|
| 711 | T_ZDrvRpMsg_Msg msg;
|
| 712 |
|
| 713 | if(NULL == buf) {
|
| 714 | return -EINVAL;
|
| 715 | }
|
| 716 | memset(&msg, 0, sizeof(msg));
|
| 717 | msg.actorID = chninfo->core_id;
|
| 718 | msg.chID = chninfo->channel_id;
|
| 719 | msg.flag |= RPMSG_WRITE_INT; //| RPMSG_WRITE_IRQLOCK;
|
| 720 | msg.buf = buf;
|
| 721 | msg.len = len;
|
| 722 | //sk_soc_info("sock_channel_write process, len=%d", len);
|
| 723 | return sockSocWrite(&msg);
|
| 724 | }
|
| 725 |
|
| 726 | /*·µ»ØÖµ´óÓÚ0£¬±íʾ¶ÁȡͨµÀ³É¹¦£»Ð¡ÓÚµÈÓÚ0±íʾͨµÀÊý¾ÝΪ¿Õ»òʧ°Ü*/
|
| 727 | static int sock_channel_read(struct sock_channel *chninfo, void *buf, unsigned int len)
|
| 728 | {
|
| 729 | T_ZDrvRpMsg_Msg msg;
|
| 730 | int ret = 0;
|
| 731 |
|
| 732 | if(NULL == buf) {
|
| 733 | return -EINVAL;
|
| 734 | }
|
| 735 | sk_soc_info("sock_channel_read enter");
|
| 736 | memset(&msg, 0, sizeof(msg));
|
| 737 | msg.actorID = chninfo->core_id;
|
| 738 | msg.chID = chninfo->channel_id;
|
| 739 | msg.buf = buf;
|
| 740 | msg.len = len;
|
| 741 |
|
| 742 | ret = sockSocRead(&msg);
|
| 743 | if (ret <= 0) {
|
| 744 | sk_soc_err("rpm read err=%d!",ret);
|
| 745 | return ret;
|
| 746 | }
|
| 747 |
|
| 748 | return ret;
|
| 749 | }
|
| 750 |
|
| 751 | static int sock_thread_enqueue_data(struct sock_rpmsg *sock_rpmsg)
|
| 752 | {
|
| 753 | unsigned long flags;
|
| 754 | struct sock_thread_info* p_main_thread_info;
|
| 755 | p_main_thread_info = &g_sock_chn_info.main_thread_info;
|
| 756 |
|
| 757 | spin_lock_irqsave(&p_main_thread_info->p_sock_lock,flags);
|
| 758 | list_add_tail(&sock_rpmsg->list, &p_main_thread_info->p_sock_list);
|
| 759 | spin_unlock_irqrestore(&p_main_thread_info->p_sock_lock,flags);
|
| 760 | sock_put_sema(&p_main_thread_info->p_sock_sem);
|
| 761 |
|
| 762 | return 0;
|
| 763 | }
|
| 764 |
|
| 765 | struct sock_rpmsg* sock_create_rpmsg(unsigned int size)
|
| 766 | {
|
| 767 | struct sock_rpmsg* sock_rpmsg;
|
| 768 |
|
| 769 | size = SOCK_DATA_ALIGN(size);
|
| 770 | size += SOCK_DATA_ALIGN(sizeof(struct sock_rpmsg));
|
| 771 | if(size > SOCK_DATA_MAX_LEN){
|
| 772 | sk_soc_err("size of data is too large, max support size is %d", SOCK_DATA_MAX_LEN-sizeof(struct sock_rpmsg));
|
| 773 | }
|
| 774 | sock_rpmsg = kzalloc(size, GFP_KERNEL);
|
| 775 | if (sock_rpmsg == NULL) {
|
| 776 | sk_soc_err("kzalloc fial!!");
|
| 777 | return NULL;
|
| 778 | }
|
| 779 | return sock_rpmsg;
|
| 780 | }
|
| 781 |
|
| 782 | static int sock_send_ipc_msg(struct sock_rpmsg* psock_rpmsg)
|
| 783 | {
|
| 784 | struct sock_rpmsg* sock_rpmsg;
|
| 785 | sock_rpmsg = sock_create_rpmsg(0);
|
| 786 | if(NULL == sock_rpmsg){
|
| 787 | sk_soc_err("kzalloc fial!!");
|
| 788 | return -1;
|
| 789 | }
|
| 790 | memcpy(sock_rpmsg, psock_rpmsg, sizeof(struct sock_rpmsg));
|
| 791 | sock_rpmsg->dir = DIR_DOWNLINK;
|
| 792 | sock_thread_enqueue_data(sock_rpmsg);
|
| 793 | //sk_soc_info("sock_send_ipc_msg write len=%d", len);
|
| 794 | return 0;
|
| 795 | }
|
| 796 |
|
| 797 | static int sock_send_ipc_msg_data(struct sock_rpmsg* psock_rpmsg)
|
| 798 | {
|
| 799 | if(NULL == psock_rpmsg){
|
| 800 | sk_soc_err("psock_rpmsg is NULL!!");
|
| 801 | return -1;
|
| 802 | }
|
| 803 |
|
| 804 | psock_rpmsg->dir = DIR_DOWNLINK;
|
| 805 | sock_thread_enqueue_data(psock_rpmsg);
|
| 806 | //sk_soc_info("sock_send_ipc_msg write len=%d", len);
|
| 807 | return 0;
|
| 808 | }
|
| 809 |
|
| 810 | static int sock_recv_ipc_msg(struct sock_rpmsg* psock_rpmsg)
|
| 811 | {
|
| 812 | struct sock_rpmsg* sock_rpmsg;
|
| 813 | sk_soc_info("sock_receive_thread sock_rpmsg.msg_type=%d,index=%d", psock_rpmsg->msg_type, psock_rpmsg->index);
|
| 814 | sock_rpmsg = sock_create_rpmsg(psock_rpmsg->data_len);
|
| 815 | if(NULL == sock_rpmsg){
|
| 816 | sk_soc_err("kzalloc fial!!");
|
| 817 | return -1;
|
| 818 | }
|
| 819 | memcpy(sock_rpmsg, psock_rpmsg, psock_rpmsg->data_len+sizeof(struct sock_rpmsg));
|
| 820 | sock_rpmsg->dir = DIR_UPLINK;
|
| 821 | sock_thread_enqueue_data(sock_rpmsg);
|
| 822 | //sk_soc_info("sock_send_ipc_msg write len=%d", len);
|
| 823 | return 0;
|
| 824 | }
|
| 825 |
|
| 826 | int sock_lookup_fd_by_sock(struct sock *sock)
|
| 827 | {
|
| 828 | struct socket *socket;
|
| 829 | socket = sock->sk_socket;
|
| 830 | sk_soc_info("sock_lookup_fd_by_sock socket=%x, socket->fd=%d\n", socket, socket->fd);
|
| 831 | return socket->fd;
|
| 832 | }
|
| 833 |
|
| 834 | static int sock_channel_clear(struct sock_channel *chninfo)
|
| 835 | {
|
| 836 | char *tbuf = NULL;
|
| 837 | unsigned int tlen = chninfo->channel_size/2;
|
| 838 | int ret = 0;
|
| 839 |
|
| 840 | tbuf = (char *)kzalloc(tlen,GFP_ATOMIC);
|
| 841 | if(IS_ERR(tbuf)) {
|
| 842 | sk_soc_err("kzalloc fail! %d byte.", tlen);
|
| 843 | return -ENOMEM;
|
| 844 | }
|
| 845 | ret = sock_channel_read(chninfo, tbuf, tlen);
|
| 846 | if(ret < 0) {
|
| 847 | sk_soc_err("zvnet_channel_read fail!");
|
| 848 | ret = 0;
|
| 849 | }
|
| 850 | kfree(tbuf);
|
| 851 | sk_soc_err("Drop channel data. %d byte.",ret);
|
| 852 |
|
| 853 | return ret;
|
| 854 | }
|
| 855 |
|
| 856 | void usock_print(struct unix_sock* usock){
|
| 857 | sk_soc_info("usock->rsock.localfd=%d", usock->rsock.localfd);
|
| 858 | sk_soc_info("usock->rsock.localsocket=%x", usock->rsock.localsocket);
|
| 859 | sk_soc_info("usock->rsock.proxyfd=%d", usock->rsock.proxyfd);
|
| 860 | sk_soc_info("usock->rsock.proxysocket=%x", usock->rsock.proxysocket);
|
| 861 | sk_soc_info("usock->rsock.remotefd=%d", usock->rsock.remotefd);
|
| 862 | sk_soc_info("usock->rsock.remotesocket=%x", usock->rsock.remotesocket);
|
| 863 | }
|
| 864 |
|
| 865 | void usock_init(struct sock* sock, int localfd, struct socket* localsocket, int proxyfd, struct socket* proxysocket, int remotefd, struct socket* remotesocket){
|
| 866 | struct unix_sock* usock;
|
| 867 | if(NULL == sock){
|
| 868 | return;
|
| 869 | }
|
| 870 | usock = unix_sk(sock);
|
| 871 | usock->rsock.localfd = localfd;
|
| 872 | usock->rsock.localsocket = localsocket;
|
| 873 | usock->rsock.proxyfd = proxyfd;
|
| 874 | usock->rsock.proxysocket = proxysocket;
|
| 875 | usock->rsock.remotefd = remotefd;
|
| 876 | usock->rsock.remotesocket = remotesocket;
|
| 877 | }
|
| 878 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 879 | //±¾µØsocket¸üк󣬸üдúÀísocketÖÐrsockÐÅÏ¢
|
| 880 | void usock_update(struct sock* sock, int localfd, struct socket* localsocket)
|
| 881 | {
|
| 882 | struct unix_sock* usock;
|
| 883 | if(NULL == sock){
|
| 884 | return;
|
| 885 | }
|
| 886 | usock = unix_sk(sock);
|
| 887 | usock->rsock.localfd = localfd;
|
| 888 | usock->rsock.localsocket = localsocket;
|
| 889 | }
|
| 890 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 891 | void usock_update_remote_proxy_socket(struct sock* sock, struct socket* remoteproxysocket)
|
| 892 | {
|
| 893 | struct unix_sock* usock;
|
| 894 | usock = unix_sk(sock);
|
| 895 | usock->rsock.remoteproxysocket = remoteproxysocket;
|
| 896 | }
|
| 897 |
|
| 898 | static struct ipc_socket * sock_create_proxy_socket_server(struct sock_rpmsg* psock_rpmsg)
|
| 899 | {
|
| 900 | struct ipc_socket *psocket_ipc = NULL;
|
| 901 | struct socket *sock;
|
| 902 |
|
| 903 | int err;
|
| 904 |
|
| 905 | sk_soc_info("clientsock=%x, serversock=%x!\n", psock_rpmsg->clientsock, psock_rpmsg->serversock);
|
| 906 | psocket_ipc = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->clientsock, psock_rpmsg->serversock);
|
| 907 | if(NULL != psocket_ipc) { //Èç¹ûÒѾ´´½¨¹ýͬһ·þÎñ¶ËµÄ´úÀí£¬Ôò²»ÔÙÖØ¸´´´½¨
|
| 908 | sk_soc_info("socket_server already exist, do not create again!\n");
|
| 909 | sock_hold(psocket_ipc->sock); //0705
|
| 910 | return psocket_ipc;
|
| 911 | }
|
| 912 |
|
| 913 | psocket_ipc = (struct ipc_socket *)kzalloc(sizeof(struct ipc_socket), GFP_ATOMIC);
|
| 914 | if(NULL == psocket_ipc){
|
| 915 | sk_soc_err("kzalloc failed!\n");
|
| 916 | return NULL;
|
| 917 | }
|
| 918 | psocket_ipc->sockfd = sys_socket(AF_UNIX, psock_rpmsg->socktype, 0); //´´½¨·þÎñ¶Ësocket´úÀí
|
| 919 | sk_soc_info("sock_create_proxy_socket_server socktype=%d, socket->fd=%d", psock_rpmsg->socktype, psocket_ipc->sockfd);
|
| 920 | //memcpy(&psocket_ipc->sock, &g_sock_rpmsg.sock, sizeof(struct sock));
|
| 921 | //psocket_ipc->socket.sk = &psocket_ipc->sock;
|
| 922 | psocket_ipc->socket = sock_get_local_socket(psocket_ipc->sockfd, &err);
|
| 923 | if(NULL != psocket_ipc->socket){
|
| 924 | sk_soc_info("sock_create_proxy_socket_server sucess\n");
|
| 925 | psocket_ipc->sock = psocket_ipc->socket->sk;
|
| 926 | psocket_ipc->proxysocket = psocket_ipc->socket;
|
| 927 | psocket_ipc->socktype = psock_rpmsg->socktype;
|
| 928 | set_bit(SOCK_IPCSOCK,&psocket_ipc->sock->sk_flags);
|
| 929 | psocket_ipc->sock->ipc_flag = 1;
|
| 930 | psocket_ipc->sock->sk_fd = psocket_ipc->sockfd;
|
| 931 | //sock_soc_set_socket_info(psocket_ipc->socket, psock_rpmsg->clientsock);
|
| 932 | sock_hold(psocket_ipc->sock); //0704
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 933 | init_peercred_proxy(psocket_ipc->sock);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 934 | //³õʼ»¯´úÀísocketµÄusockÐÅÏ¢
|
| 935 | usock_init(psocket_ipc->sock, psock_rpmsg->clientfd, psock_rpmsg->clientsock, psocket_ipc->sockfd, psocket_ipc->socket, psock_rpmsg->serverfd, psock_rpmsg->serversock);
|
| 936 | usock_update_remote_proxy_socket(psocket_ipc->sock, psock_rpmsg->serverproxysock);
|
| 937 | //usock_print(usock);
|
| 938 | }
|
| 939 | else{
|
| 940 | sk_soc_info("sock_create_proxy_socket_server failed, socket = NULL\n");
|
| 941 | }
|
| 942 | //ͬ²½·þÎñÆ÷¶ËÅäÖÃ
|
| 943 | //psocket_ipc->sock->sk_flags = g_sock_rpmsg.sock.sk_flags;
|
| 944 | //psocket_ipc->sock->sk_state = g_sock_rpmsg.sock.sk_state;
|
| 945 | //psocket_ipc->sock->sk_shutdown = g_sock_rpmsg.sock.sk_shutdown;
|
| 946 | //psocket_ipc->sock->sk_receive_queue.qlen = g_sock_rpmsg.sock.sk_receive_queue.qlen;
|
| 947 | //psocket_ipc->sock->sk_max_ack_backlog = g_sock_rpmsg.sock.sk_max_ack_backlog;
|
| 948 | psocket_ipc->localfd = psock_rpmsg->clientfd;
|
| 949 | psocket_ipc->localsocket = psock_rpmsg->clientsock;
|
| 950 | psocket_ipc->remotefd = psock_rpmsg->serverfd;
|
| 951 | psocket_ipc->remotesocket = psock_rpmsg->serversock;
|
| 952 | psocket_ipc->remoteproxyfd = psock_rpmsg->serverproxyfd;
|
| 953 | psocket_ipc->remoteproxysocket = psock_rpmsg->serverproxysock;
|
| 954 | psocket_ipc->key = psock_rpmsg->serversock;
|
| 955 | sk_soc_info("sock_create_proxy_socket_server sockfd=%d, remotefd=%d, key=%x\n", psocket_ipc->sockfd, psocket_ipc->remotefd, psocket_ipc->key);
|
| 956 | INIT_HLIST_NODE(&psocket_ipc->hlist_node);
|
| 957 | sock_soc_insert_socket(&psocket_ipc->hlist_node);
|
| 958 | return psocket_ipc;
|
| 959 | }
|
| 960 |
|
| 961 | static struct ipc_socket * sock_create_proxy_socket_client(struct sock_rpmsg* psock_rpmsg)
|
| 962 | {
|
| 963 | struct ipc_socket *psocket_ipc = NULL;
|
| 964 | struct socket *sock;
|
| 965 | struct unix_sock* usock;
|
| 966 | int err;
|
| 967 | //½öƾÕâÁ½¸ö²ÎÊý»¹²»ÄÜÈ·¶¨ÊÇ·ñͬһ¿Í»§¶ËµÄ´úÀí£¬ÒòΪ¶Ô¶Ë¿ÉÄܹرղ¢ÖØÐÂÉú³ÉÒ»¸öÏàͬµØÖ·µÄsocket
|
| 968 | if(0 == psock_rpmsg->isfistfind){
|
| 969 | psocket_ipc = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 970 | if(NULL != psocket_ipc) { //Èç¹ûÒѾ´´½¨¹ýͬһ¿Í»§¶ËµÄ´úÀí£¬Ôò²»ÔÙÖØ¸´´´½¨
|
| 971 | //sock_hold(psocket_ipc->sock); //0703
|
| 972 | return psocket_ipc;
|
| 973 | }
|
| 974 | }
|
| 975 |
|
| 976 | psocket_ipc = (struct ipc_socket *)kzalloc(sizeof(struct ipc_socket), GFP_ATOMIC);
|
| 977 | if(NULL == psocket_ipc){
|
| 978 | sk_soc_err("kzalloc failed!\n");
|
| 979 | return NULL;
|
| 980 | }
|
| 981 | sk_soc_info("sock_create_proxy_socket_client socktype=%d\n", psock_rpmsg->socktype);
|
| 982 | psocket_ipc->sockfd = sys_socket(AF_UNIX, psock_rpmsg->socktype, 0); //´´½¨¿Í»§¶Ësocket´úÀí
|
| 983 | sk_soc_info("sock_create_proxy_socket_client socket->fd=%d\n", psocket_ipc->sockfd);
|
| 984 | psocket_ipc->socket = sock_get_local_socket(psocket_ipc->sockfd, &err);
|
| 985 |
|
| 986 | //usock_print(usock);
|
| 987 |
|
| 988 | if(NULL != psocket_ipc->socket){
|
| 989 | sk_soc_info("sockfd_lookup sucess, socket=%x \n", psocket_ipc->socket);
|
| 990 | //³õʼ»¯´úÀísocketµÄusockÐÅÏ¢
|
| 991 | usock_init(psocket_ipc->socket->sk, psock_rpmsg->serverfd, psock_rpmsg->serversock, psocket_ipc->sockfd, psocket_ipc->socket, psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 992 |
|
| 993 | psocket_ipc->sock = psocket_ipc->socket->sk;
|
| 994 | set_bit(SOCK_IPCSOCK,&psocket_ipc->sock->sk_flags);
|
| 995 | psocket_ipc->sock->ipc_flag = 1;
|
| 996 | psocket_ipc->sock->sk_fd = psocket_ipc->sockfd;
|
| 997 | //sock_hold(psocket_ipc->sock); //todo: clientÊDz»ÊDz»Ó¦¸Ãµ÷ÓÃsock_hold?
|
| 998 | }
|
| 999 | else{
|
| 1000 | sk_soc_info("server socket = NULL");
|
| 1001 | }
|
| 1002 | //ÒòΪ´Ëʱ¶Ô¶ËµÄ´úÀísocket»¹Î´´´½¨£¬ËùÒÔÎÞ·¨»ñÈ¡remoteproxyfdºÍremoteproxysocket
|
| 1003 | psocket_ipc->localfd = psock_rpmsg->serverfd;
|
| 1004 | psocket_ipc->localsocket = psock_rpmsg->serversock;
|
| 1005 | psocket_ipc->remotefd = psock_rpmsg->clientfd;
|
| 1006 | psocket_ipc->remotesocket = psock_rpmsg->clientsock;
|
| 1007 | psocket_ipc->proxysocket = psocket_ipc->socket;
|
| 1008 |
|
| 1009 | psocket_ipc->key = psock_rpmsg->clientsock;
|
| 1010 | sk_soc_info("sock_create_proxy_socket_client sockfd=%d,remotefd=%d,key=%x", psocket_ipc->sockfd, psocket_ipc->remotefd,psocket_ipc->key);
|
| 1011 | INIT_HLIST_NODE(&psocket_ipc->hlist_node);
|
| 1012 | sock_soc_insert_socket(&psocket_ipc->hlist_node);
|
| 1013 | return psocket_ipc;
|
| 1014 | }
|
| 1015 |
|
| 1016 | int sock_soc_recvq_full(const struct sock *other)
|
| 1017 | {
|
| 1018 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1019 | struct ipc_socket * ipc_socket;
|
| 1020 | struct sock_rpmsg_info *psock_rpmsg_info;
|
| 1021 | int sockfd;
|
| 1022 | int result;
|
| 1023 | sk_soc_info("sock_soc_recvq_full enter");
|
| 1024 | sock_rpmsg.msg_type = MSG_TYPE_RECVQ_FULL;
|
| 1025 | sockfd = sock_lookup_fd_by_sock(other);
|
| 1026 | //sock_rpmsg.serverfd = sock_lookup_serverfd_by_clientfd(sockfd);
|
| 1027 | //ipc_socket = sock_lookup_server_by_clientfd(sockfd);
|
| 1028 | ipc_socket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1029 | if(NULL == ipc_socket){
|
| 1030 | sk_soc_info("sock_soc_recvq_full get ipc_socket faild \n");
|
| 1031 | return -1;
|
| 1032 | }
|
| 1033 | sock_rpmsg.serverfd = ipc_socket->remotefd;
|
| 1034 | sock_rpmsg.serversock = ipc_socket->remotesocket;
|
| 1035 | sock_rpmsg.clientsock = ipc_socket->localsocket;
|
| 1036 | sock_rpmsg.key = other;
|
| 1037 | psock_rpmsg_info = sock_soc_create_rpmsg_info(sock_rpmsg.key);
|
| 1038 | if(NULL == psock_rpmsg_info){
|
| 1039 | sk_soc_info("sock_soc_recvq_full create rpmsg faild \n");
|
| 1040 | return -1;
|
| 1041 | }
|
| 1042 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1043 | down_timeout(&psock_rpmsg_info->sock_sem, msecs_to_jiffies(g_sock_timeout));
|
| 1044 | result = psock_rpmsg_info->sock_rpmsg.result;
|
| 1045 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 1046 | return result;
|
| 1047 | }
|
| 1048 | EXPORT_SYMBOL_GPL(sock_soc_recvq_full);
|
| 1049 |
|
| 1050 | int sock_soc_recvq_full_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1051 | {
|
| 1052 | struct ipc_socket* ipcsocket;
|
| 1053 | struct socket *other;
|
| 1054 | int err;
|
| 1055 | int result;
|
| 1056 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1057 | sk_soc_info("sock_soc_recvq_full_proc serverfd=%d", psock_rpmsg->serverfd);
|
| 1058 | sock_rpmsg.msg_type = MSG_TYPE_RECVQ_FULL_RESULT;
|
| 1059 | sock_rpmsg.key = psock_rpmsg->key;
|
| 1060 | //other = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1061 | other = (struct socket*)psock_rpmsg->serversock;
|
| 1062 | if(sock_soc_socket_is_valid_ipc(other, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1063 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1064 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1065 | return -1;
|
| 1066 | }
|
| 1067 | sock_rpmsg.result = unix_recvq_full_proxy(other->sk);
|
| 1068 | sk_soc_info("sock_soc_recvq_full_proc result=%d\n", sock_rpmsg.result);
|
| 1069 | sock_rpmsg.serverfd = other->fd; //sock_lookup_fd_by_sock(other->sk);
|
| 1070 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1071 | return 0;
|
| 1072 | }
|
| 1073 |
|
| 1074 | int sock_soc_recvq_full_result_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1075 | {
|
| 1076 | sk_soc_info("sock_soc_recvq_full_result_proc\n");
|
| 1077 | sock_soc_rsp_proc(psock_rpmsg);
|
| 1078 | return 0;
|
| 1079 | }
|
| 1080 |
|
| 1081 | int sock_soc_recvq_full_lockless_and_dead(const struct sock *other)
|
| 1082 | {
|
| 1083 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1084 | struct ipc_socket *ipc_socket;
|
| 1085 | struct sock_rpmsg_info *psock_rpmsg_info;
|
| 1086 | int sockfd;
|
| 1087 | int result;
|
| 1088 | sk_soc_info("sock_soc_recvq_full_lockless_and_dead\n");
|
| 1089 | sock_rpmsg.msg_type = MSG_TYPE_RECVQ_FULL_LOCKLESS_AND_DEAD;
|
| 1090 | sockfd = sock_lookup_fd_by_sock(other);
|
| 1091 | //sock_rpmsg.serverfd = sock_lookup_serverfd_by_clientfd(sockfd);
|
| 1092 | //ipc_socket = sock_lookup_server_by_clientfd(sockfd);
|
| 1093 | ipc_socket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1094 | if(NULL == ipc_socket){
|
| 1095 | sk_soc_info("sock_soc_recvq_full_lockless_and_dead get ipc_socket faild \n");
|
| 1096 | return -1;
|
| 1097 | }
|
| 1098 | sock_rpmsg.serverfd = ipc_socket->remotefd;
|
| 1099 | sock_rpmsg.serversock = ipc_socket->remotesocket;
|
| 1100 | sock_rpmsg.clientsock = ipc_socket->localsocket;
|
| 1101 | sock_rpmsg.key = other;
|
| 1102 | psock_rpmsg_info = sock_soc_create_rpmsg_info(sock_rpmsg.key);
|
| 1103 | if(NULL == psock_rpmsg_info){
|
| 1104 | sk_soc_info("sock_soc_recvq_full_lockless_and_dead create rpmsg faild \n");
|
| 1105 | return -1;
|
| 1106 | }
|
| 1107 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1108 | down_timeout(&psock_rpmsg_info->sock_sem, msecs_to_jiffies(g_sock_timeout));
|
| 1109 | result = psock_rpmsg_info->sock_rpmsg.result;
|
| 1110 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 1111 | return result;
|
| 1112 | }
|
| 1113 | EXPORT_SYMBOL_GPL(sock_soc_recvq_full_lockless_and_dead);
|
| 1114 |
|
| 1115 | int sock_soc_recvq_full_lockless_and_dead_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1116 | {
|
| 1117 | struct ipc_socket* ipcsocket;
|
| 1118 | struct socket *other;
|
| 1119 | int err;
|
| 1120 | int result;
|
| 1121 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1122 | sk_soc_info("sock_soc_recvq_full_lockless_and_dead_proc");
|
| 1123 | sock_rpmsg.msg_type = MSG_TYPE_RECVQ_FULL_LOCKLESS_AND_DEAD_RESULT;
|
| 1124 | sock_rpmsg.key = psock_rpmsg->key;
|
| 1125 | //other = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1126 | other = (struct socket*)psock_rpmsg->serversock;
|
| 1127 | if(sock_soc_socket_is_valid_ipc(other, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1128 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1129 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1130 | return -1;
|
| 1131 | }
|
| 1132 | sock_rpmsg.result = unix_recvq_full_proxy_lockless_and_deadstate(other->sk);
|
| 1133 | sock_rpmsg.serverfd = sock_lookup_fd_by_sock(other->sk);
|
| 1134 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1135 | return 0;
|
| 1136 | }
|
| 1137 |
|
| 1138 | int sock_soc_recvq_full_lockless_and_dead_result_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1139 | {
|
| 1140 | sk_soc_info("sock_soc_recvq_full_lockless_and_dead_result_proc");
|
| 1141 | sock_soc_rsp_proc(psock_rpmsg);
|
| 1142 | return 0;
|
| 1143 | }
|
| 1144 | /*
|
| 1145 | ** sock: ±¾µØsocket
|
| 1146 | ** other:¶Ô¶ËsocketµÄ±¾µØ´úÀí
|
| 1147 | */
|
| 1148 | int sock_soc_set_peer(struct sock *sock, struct sock *other)
|
| 1149 | {
|
| 1150 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1151 | struct ipc_socket *ipc_socket;
|
| 1152 | int sockfd;
|
| 1153 | sock_rpmsg.msg_type = MSG_TYPE_SET_PEER;
|
| 1154 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 1155 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 1156 | sockfd = sock_lookup_fd_by_sock(other);
|
| 1157 | //sock_rpmsg.serverfd = sock_lookup_serverfd_by_clientfd(sockfd);
|
| 1158 | //ipc_socket = sock_lookup_server_by_clientfd(sockfd);
|
| 1159 | ipc_socket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1160 | if(NULL == ipc_socket){
|
| 1161 | sk_soc_info("sock_soc_set_peer get ipc_socket faild \n");
|
| 1162 | return -1;
|
| 1163 | }
|
| 1164 | sock_rpmsg.serverfd = ipc_socket->remotefd;
|
| 1165 | sock_rpmsg.serversock = ipc_socket->remotesocket;
|
| 1166 | sk_soc_info("sock_soc_set_peer clientfd=%d, serverfd=%d\n", sock_rpmsg.clientfd, sock_rpmsg.serverfd);
|
| 1167 |
|
| 1168 | unix_peer(sock) = other;
|
| 1169 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1170 | return 0;
|
| 1171 | }
|
| 1172 | EXPORT_SYMBOL_GPL(sock_soc_set_peer);
|
| 1173 |
|
| 1174 | int sock_soc_set_peer_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1175 | {
|
| 1176 | struct ipc_socket* ipcsocket;
|
| 1177 | struct socket *clientsocket;
|
| 1178 | struct socket *serversocket;
|
| 1179 | struct sock *sock;
|
| 1180 | struct sock *other;
|
| 1181 | int err;
|
| 1182 | sk_soc_info("sock_soc_set_peer_proc clientfd=%d, serverfd=%d", psock_rpmsg->clientfd, psock_rpmsg->serverfd);
|
| 1183 | //¶ÔÓÚ·þÎñ¶ËÀ´Ëµ,serversockÊôÓÚ±¾µØsocket£¬clientsockÊôÓÚÔ¶¶Ësocket
|
| 1184 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1185 | if(ipcsocket == NULL){
|
| 1186 | sk_soc_info("sock_soc_set_peer_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1187 | return -1;
|
| 1188 | }
|
| 1189 | //clientsocket = (struct socket*)psock_rpmsg->clientsock;
|
| 1190 | sock = ipcsocket->sock;
|
| 1191 | //serversocket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1192 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 1193 | if(sock_soc_socket_is_valid_ipc(serversocket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1194 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1195 | return -1;
|
| 1196 | }
|
| 1197 | other = serversocket->sk;
|
| 1198 |
|
| 1199 | unix_peer(sock) = other;
|
| 1200 | sock_hold(other);
|
| 1201 | //unix_peer(other) = sock; //0703
|
| 1202 | return 0;
|
| 1203 | }
|
| 1204 |
|
| 1205 | /*½«ËùÓÐsocket->peer==sockµÄsocket,È«²¿¸üÐÂΪsocket->peer=newsock*/
|
| 1206 | //¸Ã½Ó¿ÚÓÃÓÚ·þÎñ¶Ë֪ͨ¿Í»§¶Ë
|
| 1207 | int sock_soc_update_peer(struct socket *sock, struct socket *newsock)
|
| 1208 | {
|
| 1209 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1210 | struct sock* proxysock;
|
| 1211 | struct ipc_socket* ipcsocket;
|
| 1212 | int sockfd;
|
| 1213 | struct unix_sock* usock;
|
| 1214 | //newsock->sk->peerÖ¸ÏòµÄÊǿͻ§¶Ë´úÀísock
|
| 1215 | proxysock = unix_peer(newsock->sk);
|
| 1216 | usock = unix_sk(proxysock);
|
| 1217 | usock->rsock.localsocket = newsock;
|
| 1218 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(proxysock);
|
| 1219 | if(NULL != ipcsocket){
|
| 1220 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1221 | ipcsocket->localsocket = newsock;
|
| 1222 | sk_soc_info("remotesocket=%x, localsocket=%x", ipcsocket->remotesocket, ipcsocket->localsocket);
|
| 1223 | }else{
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 1224 | sk_soc_info("sock_soc_get_ipcsocket_by_proxysock failed, proxysock=%x, sock=%x", proxysock, sock);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1225 | return -1;
|
| 1226 | }
|
| 1227 | sk_soc_info("sock=%x, newsock=%x", sock, newsock);
|
| 1228 | sock_rpmsg.msg_type = MSG_TYPE_UPDATE_PEER;
|
| 1229 | sock_rpmsg.clientfd = sock->fd;
|
| 1230 | sock_rpmsg.clientsock = sock;
|
| 1231 | sock_rpmsg.newclientfd = newsock->fd;
|
| 1232 | sock_rpmsg.newsock = newsock;
|
| 1233 | sock_soc_del_socket_peer(sock, ipcsocket->proxysocket);
|
| 1234 | sock_soc_insert_socket_peer(newsock, ipcsocket->proxysocket);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 1235 | usock_update(ipcsocket->sock, newsock->fd, newsock);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1236 | //newsock->peer = sock->peer; //0706
|
| 1237 | //sock->peer = NULL; //0706
|
| 1238 | sock_rpmsg.key = sock_rpmsg.serversock;
|
| 1239 | sk_soc_info("clientfd=%d, newclientfd=%d\n", sock_rpmsg.clientfd, sock_rpmsg.newclientfd);
|
| 1240 | //sock_soc_del_socket_info(proxysock->sk_socket, sock); //ɾ³ý¾ÉµÄÐÅÏ¢
|
| 1241 | //sock_soc_set_socket_info(proxysock->sk_socket, newsock); //Ìí¼ÓеÄÐÅÏ¢
|
| 1242 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1243 | return 0;
|
| 1244 | }
|
| 1245 |
|
| 1246 | EXPORT_SYMBOL_GPL(sock_soc_update_peer);
|
| 1247 |
|
| 1248 | int sock_soc_update_peer_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1249 | {
|
| 1250 | struct ipc_socket* ipcsocket;
|
| 1251 | struct socket *clientsocket;
|
| 1252 | struct socket *serversocket;
|
| 1253 | struct sock *sock;
|
| 1254 | struct sock *other;
|
| 1255 | struct unix_sock* usock;
|
| 1256 | int err;
|
| 1257 | sk_soc_info("sock_soc_update_peer_proc clientfd=%d, newclientfd=%d", psock_rpmsg->clientfd, psock_rpmsg->newclientfd);
|
| 1258 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1259 | if(ipcsocket == NULL){
|
| 1260 | sk_soc_info("sock_soc_update_peer_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1261 | return -1;
|
| 1262 | }
|
| 1263 | sk_soc_info("sock_soc_update_peer_proc sock=%x, newsock=%x", ipcsocket->remotesocket, psock_rpmsg->newsock);
|
| 1264 | ipcsocket->remotefd = psock_rpmsg->newclientfd;
|
| 1265 | ipcsocket->remotesocket = psock_rpmsg->newsock;
|
| 1266 | ipcsocket->key = psock_rpmsg->newsock;
|
| 1267 | usock = unix_sk(ipcsocket->proxysocket->sk);
|
| 1268 | usock->rsock.remotefd = psock_rpmsg->newclientfd;
|
| 1269 | usock->rsock.remotesocket = psock_rpmsg->newsock;
|
| 1270 | sock_soc_rsp_proc(psock_rpmsg);//ÊÍ·ÅconnectµÈ´ýµÄÐźÅÁ¿
|
| 1271 | return 0;
|
| 1272 | }
|
| 1273 |
|
| 1274 | void sock_soc_sock_hold(struct sock *other)
|
| 1275 | {
|
| 1276 | struct ipc_socket *psocket_ipc = NULL;
|
| 1277 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1278 | sock_rpmsg.msg_type = MSG_TYPE_SOCK_HOLD;
|
| 1279 | //dump_stack();
|
| 1280 | //²éÕÒ·þÎñÆ÷¶Ë´úÀísocketÏà¹ØÐÅÏ¢
|
| 1281 | psocket_ipc = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1282 | if(psocket_ipc == NULL){
|
| 1283 | sk_soc_info("sock_soc_sock_hold failed, other->fd=%d\n ", other->sk_fd);
|
| 1284 | return;
|
| 1285 | }
|
| 1286 | //·þÎñÆ÷¶Ësocket fd
|
| 1287 | sock_rpmsg.serverfd = psocket_ipc->remotefd;
|
| 1288 | sock_rpmsg.serversock = psocket_ipc->remotesocket;
|
| 1289 | sock_rpmsg.clientsock = psocket_ipc->localsocket;
|
| 1290 | sk_soc_info("sock_soc_sock_hold serverfd=%d \n", sock_rpmsg.serverfd);
|
| 1291 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1292 | }
|
| 1293 |
|
| 1294 | int sock_soc_sock_hold_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1295 | {
|
| 1296 | struct socket* serversocket;
|
| 1297 | struct sock* other;
|
| 1298 |
|
| 1299 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 1300 | if(sock_soc_socket_is_valid_ipc(serversocket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1301 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1302 | return -1;
|
| 1303 | }
|
| 1304 | other = serversocket->sk;
|
| 1305 |
|
| 1306 | sk_soc_info("sock_soc_sock_hold_proc serverfd=%d \n", psock_rpmsg->serverfd);
|
| 1307 | sock_hold(other);
|
| 1308 | return 0;
|
| 1309 | }
|
| 1310 |
|
| 1311 | int sock_soc_sock_put(struct sock *other)
|
| 1312 | {
|
| 1313 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1314 | int sockfd;
|
| 1315 | struct ipc_socket *ipc_socket;
|
| 1316 | sock_rpmsg.msg_type = MSG_TYPE_SOCK_PUT;
|
| 1317 | //other->sk_socket¿ÉÄÜÒѱ»ÖÃΪnull
|
| 1318 | if(!other->sk_socket){
|
| 1319 | sockfd = other->sk_fd;
|
| 1320 | }
|
| 1321 | else{
|
| 1322 | sockfd = sock_lookup_fd_by_sock(other);
|
| 1323 | }
|
| 1324 |
|
| 1325 | //sock_rpmsg.serverfd = sock_lookup_serverfd_by_clientfd(sockfd);
|
| 1326 | //ipc_socket = sock_lookup_server_by_clientfd(sockfd);
|
| 1327 | ipc_socket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1328 | if(NULL == ipc_socket){
|
| 1329 | sk_soc_info("sock_soc_sock_put get ipc_socket faild \n");
|
| 1330 | return -1;
|
| 1331 | }
|
| 1332 | sock_rpmsg.serverfd = ipc_socket->remotefd;
|
| 1333 | sock_rpmsg.serversock = ipc_socket->remotesocket;
|
| 1334 | sock_rpmsg.clientsock = ipc_socket->localsocket;
|
| 1335 | sk_soc_info("sock_soc_sock_put serverfd=%d\n", sock_rpmsg.serverfd);
|
| 1336 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1337 | return 0;
|
| 1338 | }
|
| 1339 | EXPORT_SYMBOL_GPL(sock_soc_sock_put);
|
| 1340 |
|
| 1341 | int sock_soc_sock_put_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1342 | {
|
| 1343 | struct socket *other;
|
| 1344 | int err;
|
| 1345 | //other = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1346 | other = (struct socket*)psock_rpmsg->serversock;
|
| 1347 | if(sock_soc_socket_is_valid_ipc(other, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1348 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1349 | return -1;
|
| 1350 | }
|
| 1351 | sk_soc_info("sock_soc_sock_put_proc serversock=%x, serverfd=%d",other, psock_rpmsg->serverfd);
|
| 1352 | if(other->sk){
|
| 1353 | sock_put(other->sk);
|
| 1354 | }
|
| 1355 |
|
| 1356 | return 0;
|
| 1357 | }
|
| 1358 |
|
| 1359 | int sock_soc_msg_send(struct sock *sock, struct sock *other, struct msghdr *msg, size_t len)
|
| 1360 | {
|
| 1361 | struct ipc_socket *psocket_ipc = NULL;
|
| 1362 | //struct sock_rpmsg sock_rpmsg = {0};
|
| 1363 | //sock_rpmsg.msg_type = MSG_TYPE_SEND_MSG;
|
| 1364 | struct sock_rpmsg* psock_rpmsg =NULL;
|
| 1365 |
|
| 1366 | psock_rpmsg = sock_create_rpmsg(len);
|
| 1367 | if(psock_rpmsg == NULL){
|
| 1368 | sk_soc_err("sock_soc_msg_send failed, sock_create_rpmsg failed\n ");
|
| 1369 | return -1;
|
| 1370 | }
|
| 1371 | psock_rpmsg->msg_type = MSG_TYPE_SEND_MSG;
|
| 1372 | //¿Í»§¶Ësocket fd
|
| 1373 | psock_rpmsg->clientfd = sock_lookup_fd_by_sock(sock);
|
| 1374 | psock_rpmsg->clientsock = sock->sk_socket;
|
| 1375 | //²éÕÒ·þÎñÆ÷¶Ë´úÀísocketÏà¹ØÐÅÏ¢
|
| 1376 | psocket_ipc = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1377 | if(psocket_ipc == NULL){
|
| 1378 | sk_soc_info("sock_soc_msg_send failed, other->sk_fd=%d\n ", other->sk_fd);
|
| 1379 | kfree(psock_rpmsg);
|
| 1380 | return -1;
|
| 1381 | }
|
| 1382 | //·þÎñÆ÷¶Ësocket fd
|
| 1383 | psock_rpmsg->serverfd = psocket_ipc->remotefd;
|
| 1384 | psock_rpmsg->serversock = psocket_ipc->remotesocket;
|
| 1385 | psock_rpmsg->clientsock = psocket_ipc->localsocket;
|
| 1386 |
|
| 1387 | psock_rpmsg->msg_flags = msg->msg_flags;
|
| 1388 | //¿½±´·¢Ë͵ÄÊý¾Ý
|
| 1389 | memcpy_fromiovec(psock_rpmsg->data, msg->msg_iov, len);
|
| 1390 | psock_rpmsg->data_len = len;
|
| 1391 | //strcpy(sock_rpmsg.data, "test");
|
| 1392 | //sock_rpmsg.data_len = 4;
|
| 1393 | //¿½±´socketµØÖ·
|
| 1394 | if(msg->msg_namelen > 0){
|
| 1395 | memcpy(&psock_rpmsg->sockaddr, (struct sockaddr_un*)msg->msg_name, msg->msg_namelen);
|
| 1396 | }
|
| 1397 | psock_rpmsg->addr_len = msg->msg_namelen;
|
| 1398 | sk_soc_info("sock_soc_msg_send clientfd=%d, serverfd=%d, data=%s, len=%d\n", psock_rpmsg->clientfd, psock_rpmsg->serverfd, psock_rpmsg->data, len);
|
| 1399 | sock_send_ipc_msg_data(psock_rpmsg);
|
| 1400 | return 0;
|
| 1401 | }
|
| 1402 |
|
| 1403 | int sock_soc_msg_send_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1404 | {
|
| 1405 | struct ipc_socket* clientsocket;
|
| 1406 | struct socket* serversocket;
|
| 1407 | struct sock* sock;
|
| 1408 | struct sock* other;
|
| 1409 | char __user * p,q;
|
| 1410 | mm_segment_t old_fs;
|
| 1411 | struct msghdr msg;
|
| 1412 | unsigned int msg_flags;
|
| 1413 | struct iovec iov;
|
| 1414 | int err;
|
| 1415 |
|
| 1416 | //serversocket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1417 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 1418 | if(sock_soc_socket_is_valid_ipc(serversocket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1419 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1420 | return -1;
|
| 1421 | }
|
| 1422 | other = serversocket->sk;
|
| 1423 |
|
| 1424 | clientsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1425 | if(clientsocket == NULL){
|
| 1426 | sk_soc_info("sock_soc_msg_send_proc failed, serversock=%x,clientsock=%x\n ", psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1427 | return -1;
|
| 1428 | }
|
| 1429 | sk_soc_info("sock_soc_msg_send_proc, serversock=%x,clientsock=%x\n ", psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1430 | sock = clientsocket->sock;
|
| 1431 |
|
| 1432 | sk_soc_info("sock_soc_msg_send_proc clientfd=%d, serverfd=%d, len=%d", psock_rpmsg->clientfd, psock_rpmsg->serverfd, psock_rpmsg->data_len);
|
| 1433 |
|
| 1434 | old_fs = get_fs();
|
| 1435 | set_fs(KERNEL_DS);
|
| 1436 | if(psock_rpmsg->addr_len > 0){
|
| 1437 | p = (__force struct sockaddr_un __user *)(&psock_rpmsg->sockaddr);
|
| 1438 | }
|
| 1439 | q = (__force const char __user *)(psock_rpmsg->data);
|
| 1440 | //sys_sendto(psock_rpmsg->serverfd, psock_rpmsg->data, psock_rpmsg->data_len, psock_rpmsg->msg_flags, NULL, 0);
|
| 1441 | if(psock_rpmsg->addr_len > 0){
|
| 1442 | sys_sendto(clientsocket->sockfd, psock_rpmsg->data, psock_rpmsg->data_len, psock_rpmsg->msg_flags, &psock_rpmsg->sockaddr, psock_rpmsg->addr_len);
|
| 1443 | }else{
|
| 1444 | sys_sendto(clientsocket->sockfd, psock_rpmsg->data, psock_rpmsg->data_len, psock_rpmsg->msg_flags, NULL, 0);
|
| 1445 | }
|
| 1446 | set_fs(old_fs);
|
| 1447 | //other->sk_data_ready(other, psock_rpmsg->data_len);
|
| 1448 | //sock_put(other);
|
| 1449 | return 0;
|
| 1450 | }
|
| 1451 |
|
| 1452 | long sock_wait_for_peer(struct sock *sock, struct sock *other, long timeo)
|
| 1453 | {
|
| 1454 | struct ipc_socket * ipcsocket;
|
| 1455 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1456 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 1457 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 1458 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1459 | if(ipcsocket == NULL){
|
| 1460 | sk_soc_info("sock_wait_for_peer failed, other->fd=%d\n ", other->sk_fd);
|
| 1461 | return -1;
|
| 1462 | }
|
| 1463 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1464 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1465 | sock_rpmsg.msg_type = MSG_TYPE_WAIT_FOR_PEER;
|
| 1466 | sock_rpmsg.timeo = timeo;
|
| 1467 | sk_soc_info("sock_wait_for_peer clientfd=%d, serverfd=%d", sock_rpmsg.clientfd, sock_rpmsg.serverfd);
|
| 1468 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1469 | return 0;
|
| 1470 | }
|
| 1471 |
|
| 1472 | static int sock_wait_for_peer_thread(void *argv)
|
| 1473 | {
|
| 1474 | struct peer_sock_info* peer_info = (struct peer_sock_info*)argv;
|
| 1475 | sk_soc_info("sock_wait_for_peer_thread enter");
|
| 1476 | unix_wait_for_peer_proxy(peer_info->peersock, peer_info->timeo);
|
| 1477 | return 0;
|
| 1478 | }
|
| 1479 |
|
| 1480 | int sock_wait_for_peer_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1481 | {
|
| 1482 | struct ipc_socket *socket_ipc;
|
| 1483 | struct task_struct *th = NULL;
|
| 1484 | struct socket* clientsocket;
|
| 1485 | struct socket* serversocket;
|
| 1486 | int err;
|
| 1487 | socket_ipc = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1488 | if(socket_ipc == NULL){
|
| 1489 | sk_soc_info("sock_wait_for_peer_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1490 | return -1;
|
| 1491 | }
|
| 1492 | struct peer_sock_info* peer_info = (struct peer_sock_info *)kzalloc(sizeof(struct peer_sock_info), GFP_ATOMIC);
|
| 1493 | if(NULL == peer_info){
|
| 1494 | sk_soc_err("kzalloc failed!");
|
| 1495 | return -1;
|
| 1496 | }
|
| 1497 | peer_info->timeo = psock_rpmsg->timeo;
|
| 1498 | clientsocket= sock_get_local_socket(socket_ipc->sockfd, &err);
|
| 1499 | if(NULL == clientsocket){
|
| 1500 | kfree(peer_info);
|
| 1501 | sk_soc_err("clientsocket is NULL!");
|
| 1502 | return -1;
|
| 1503 | }
|
| 1504 | //clientsocket = (struct socket*)psock_rpmsg->clientsock;
|
| 1505 | peer_info->sock = clientsocket->sk;
|
| 1506 | //serversocket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1507 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 1508 | if(sock_soc_socket_is_valid_other(serversocket) == -1){ //serversockÒѹرÕ
|
| 1509 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1510 | return -1;
|
| 1511 | }
|
| 1512 | peer_info->peersock = serversocket->sk;
|
| 1513 | sk_soc_info("sock_wait_for_peer_proc clientfd=%d, serverfd=%d", socket_ipc->sockfd, psock_rpmsg->serverfd);
|
| 1514 | th = kthread_run(sock_wait_for_peer_thread, peer_info, "wait_for_peer");
|
| 1515 | if (IS_ERR(th)) {
|
| 1516 | sk_soc_err("Unable to start receive thread.");
|
| 1517 | return PTR_ERR(th);
|
| 1518 | }
|
| 1519 | return 0;
|
| 1520 | }
|
| 1521 |
|
| 1522 | int sock_soc_unix_peer_clear(struct sock *sk)
|
| 1523 | {
|
| 1524 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1525 | struct ipc_socket *socket_ipc;
|
| 1526 | sk_soc_info("sock_soc_unix_peer_clear enter\n");
|
| 1527 | //socket_ipc = sock_soc_get_ipcsocket_by_fd(psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1528 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sk);
|
| 1529 | sock_rpmsg.clientsock = sk->sk_socket;
|
| 1530 | sock_rpmsg.msg_type = MSG_TYPE_PEER_CLEAR;
|
| 1531 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1532 | return 0;
|
| 1533 | }
|
| 1534 |
|
| 1535 | int sock_soc_unix_peer_clear_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1536 | {
|
| 1537 | struct socket* socket;
|
| 1538 | struct sock* sock;
|
| 1539 | int err;
|
| 1540 | sk_soc_info("sock_soc_unix_peer_clear_proc enter");
|
| 1541 | //socket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1542 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1543 | if(sock_soc_socket_is_valid_other(socket) == -1){ //serversockÒѹرÕ
|
| 1544 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1545 | return -1;
|
| 1546 | }
|
| 1547 | sock = socket->sk;
|
| 1548 | if(sock == NULL){
|
| 1549 | sk_soc_info("sock_soc_unix_peer_clear_proc sock is NULL");
|
| 1550 | return -1;
|
| 1551 | }
|
| 1552 | unix_sk(sock)->peer = NULL;
|
| 1553 | return 0;
|
| 1554 | }
|
| 1555 |
|
| 1556 | int sock_soc_wake_up_interruptible_poll(struct sock *sk)
|
| 1557 | {
|
| 1558 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1559 |
|
| 1560 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sk);
|
| 1561 | sock_rpmsg.clientsock = sk->sk_socket;
|
| 1562 | sock_rpmsg.msg_type = MSG_TYPE_WAKE_UP_INTERRUPTIBLE_POLL;
|
| 1563 | sk_soc_info("sock_soc_wake_up_interruptible_poll clientfd=%d", sock_rpmsg.clientfd);
|
| 1564 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1565 | return 0;
|
| 1566 | }
|
| 1567 |
|
| 1568 | int sock_soc_wake_up_interruptible_poll_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1569 | {
|
| 1570 | struct socket* socket;
|
| 1571 | struct sock* sock;
|
| 1572 | int err;
|
| 1573 | //serverfd = sock_lookup_serverfd_by_clientfd(psock_rpmsg->clientfd);
|
| 1574 | //socket = sock_get_local_socket(serverfd, &err);
|
| 1575 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1576 | if(sock_soc_socket_is_valid_other(socket) == -1){ //serversockÒѹرÕ
|
| 1577 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1578 | return -1;
|
| 1579 | }
|
| 1580 | sock = socket->sk;
|
| 1581 | if(sock == NULL){
|
| 1582 | sk_soc_info("sock_soc_wake_up_interruptible_poll_proc sock is NULL");
|
| 1583 | return -1;
|
| 1584 | }
|
| 1585 |
|
| 1586 | wake_up_interruptible_poll(sk_sleep(sock),
|
| 1587 | POLLOUT |
|
| 1588 | POLLWRNORM |
|
| 1589 | POLLWRBAND);
|
| 1590 | return 0;
|
| 1591 | }
|
| 1592 |
|
| 1593 | int sock_soc_sk_data_ready(struct sock *sk)
|
| 1594 | {
|
| 1595 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1596 | struct ipc_socket * ipcsocket;
|
| 1597 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(sk);
|
| 1598 | if(ipcsocket == NULL){
|
| 1599 | sk_soc_info("sock_soc_sk_data_ready failed, sk->fd=%d\n ", sk->sk_fd);
|
| 1600 | return -1;
|
| 1601 | }
|
| 1602 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1603 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1604 | sock_rpmsg.clientsock = ipcsocket->localsocket;
|
| 1605 | sk_soc_info("sock_soc_sk_data_ready serverfd=%d", sock_rpmsg.serverfd);
|
| 1606 | sock_rpmsg.msg_type = MSG_TYPE_DATA_READY;
|
| 1607 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1608 | return 0;
|
| 1609 | }
|
| 1610 |
|
| 1611 | int sock_soc_sk_data_ready_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1612 | {
|
| 1613 | struct socket* socket;
|
| 1614 | struct sock* sock;
|
| 1615 | int err;
|
| 1616 | //socket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1617 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1618 | if(sock_soc_socket_is_valid_ipc(socket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1619 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1620 | return -1;
|
| 1621 | }
|
| 1622 | sk_soc_info("sock_soc_sk_data_ready_proc serverfd=%d", psock_rpmsg->serverfd);
|
| 1623 | sock = socket->sk;
|
| 1624 | if(sock == NULL){
|
| 1625 | sk_soc_info("sock_soc_sk_data_ready_proc sock is NULL");
|
| 1626 | return -1;
|
| 1627 | }
|
| 1628 | sock->sk_data_ready(sock, 1);
|
| 1629 | return 0;
|
| 1630 | }
|
| 1631 |
|
| 1632 | int sock_sync_ipc_socket(struct sock_elem_flag* elem_flag, struct sock *other)
|
| 1633 | {
|
| 1634 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1635 | struct ipc_socket * ipcsocket;
|
| 1636 | sock_rpmsg.msg_type = MSG_TYPE_SYNC_IPC_SOCKET;
|
| 1637 | memcpy(&sock_rpmsg.elem, elem_flag, sizeof(struct sock_elem_flag));
|
| 1638 | //memcpy(&sock_rpmsg.sock, other, sizeof(struct sock));
|
| 1639 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1640 | if(ipcsocket == NULL){
|
| 1641 | sk_soc_info("sock_sync_ipc_socket failed, other->fd=%d\n ", other->sk_fd);
|
| 1642 | return -1;
|
| 1643 | }
|
| 1644 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1645 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1646 | sock_rpmsg.clientsock = ipcsocket->localsocket;
|
| 1647 | sk_soc_info("sock_sync_ipc_socket serverfd=%d", sock_rpmsg.serverfd);
|
| 1648 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1649 |
|
| 1650 | return 0;
|
| 1651 | }
|
| 1652 |
|
| 1653 | int sock_sync_ipc_socket_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1654 | {
|
| 1655 | struct socket* socket;
|
| 1656 | struct sock *other;
|
| 1657 | int err;
|
| 1658 | //socket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1659 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1660 | if(NULL == socket){
|
| 1661 | return -1;
|
| 1662 | }
|
| 1663 | if(sock_soc_socket_is_valid_ipc(socket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1664 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1665 | return -1;
|
| 1666 | }
|
| 1667 | other = socket->sk;
|
| 1668 | if(other == NULL){
|
| 1669 | sk_soc_info("sock_sync_ipc_socket_proc other is NULL");
|
| 1670 | return -1;
|
| 1671 | }
|
| 1672 | sk_soc_info("sock_sync_ipc_socket_proc serverfd=%d", psock_rpmsg->serverfd);
|
| 1673 | if(psock_rpmsg->elem.sk_err){
|
| 1674 | //other->sk_err = psock_rpmsg->sock.sk_err;
|
| 1675 | }
|
| 1676 |
|
| 1677 | if(psock_rpmsg->elem.sk_error_report){
|
| 1678 | other->sk_error_report(other);
|
| 1679 | }
|
| 1680 |
|
| 1681 | return 0;
|
| 1682 | }
|
| 1683 |
|
| 1684 | int sock_soc_get_state(struct sock_elem_flag* elem_flag, struct sock *other)
|
| 1685 | {
|
| 1686 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1687 | struct ipc_socket * ipcsocket;
|
| 1688 | struct sock_rpmsg_info *psock_rpmsg_info;
|
| 1689 | sock_rpmsg.msg_type = MSG_TYPE_GET_SOCKET_STATES;
|
| 1690 | memcpy(&sock_rpmsg.elem, elem_flag, sizeof(struct sock_elem_flag));
|
| 1691 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1692 | if(ipcsocket == NULL){
|
| 1693 | sk_soc_info("sock_soc_get_state failed, other->fd=%d\n ", other->sk_fd);
|
| 1694 | return -1;
|
| 1695 | }
|
| 1696 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1697 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1698 | sock_rpmsg.clientsock = ipcsocket->localsocket;
|
| 1699 | sock_rpmsg.key = other;
|
| 1700 | sk_soc_info("sock_soc_get_state serverfd=%d", sock_rpmsg.serverfd);
|
| 1701 |
|
| 1702 | psock_rpmsg_info = sock_soc_create_rpmsg_info(sock_rpmsg.key);
|
| 1703 | if(NULL == psock_rpmsg_info){
|
| 1704 | sk_soc_info("sock_soc_get_state create rpmsg faild \n");
|
| 1705 | return -1;
|
| 1706 | }
|
| 1707 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1708 | down_timeout(&psock_rpmsg_info->sock_sem, msecs_to_jiffies(g_sock_timeout));
|
| 1709 |
|
| 1710 | if(psock_rpmsg_info->sock_rpmsg.elem.skstate){
|
| 1711 | other->sk_state = psock_rpmsg_info->sock_rpmsg.elem.skstate;
|
| 1712 | sk_soc_info("sk_state=%d", other->sk_state);
|
| 1713 | }
|
| 1714 |
|
| 1715 | if(psock_rpmsg_info->sock_rpmsg.elem.skshutdown){
|
| 1716 | other->sk_shutdown = psock_rpmsg_info->sock_rpmsg.elem.skshutdown;
|
| 1717 | sk_soc_info("sk_shutdown=%d", other->sk_shutdown);
|
| 1718 | }
|
| 1719 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 1720 | sk_soc_info("sock_soc_get_state end");
|
| 1721 | return 0;
|
| 1722 | }
|
| 1723 |
|
| 1724 | int sock_soc_get_state_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1725 | {
|
| 1726 | struct socket* socket;
|
| 1727 | struct sock *other;
|
| 1728 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1729 | int err;
|
| 1730 | sock_rpmsg.msg_type = MSG_TYPE_GET_SOCKET_STATES_RESULT;
|
| 1731 | sock_rpmsg.key = psock_rpmsg->key;
|
| 1732 | sk_soc_info("sock_soc_get_state_proc serverfd=%d", psock_rpmsg->serverfd);
|
| 1733 | //socket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1734 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1735 | if(sock_soc_socket_is_valid_ipc(socket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1736 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1737 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1738 | return -1;
|
| 1739 | }
|
| 1740 | if(NULL != socket){
|
| 1741 | sk_soc_info("sock_soc_get_state_proc sucess");
|
| 1742 | other = socket->sk;
|
| 1743 | if(other == NULL){
|
| 1744 | sk_soc_info("sock_soc_get_state_proc other is NULL");
|
| 1745 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1746 | return -1;
|
| 1747 | }
|
| 1748 | if(psock_rpmsg->elem.skstate){
|
| 1749 | sock_rpmsg.elem.skstate = other->sk_state;
|
| 1750 | sk_soc_info("sk_state=%d", other->sk_state);
|
| 1751 | }
|
| 1752 |
|
| 1753 | if(psock_rpmsg->elem.skshutdown){
|
| 1754 | sock_rpmsg.elem.skshutdown = other->sk_shutdown;
|
| 1755 | sk_soc_info("sk_shutdown=%d", other->sk_shutdown);
|
| 1756 | }
|
| 1757 | }
|
| 1758 | else
|
| 1759 | {
|
| 1760 | sk_soc_info("sock_soc_get_state_proc failed");
|
| 1761 | }
|
| 1762 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1763 | return 0;
|
| 1764 | }
|
| 1765 |
|
| 1766 | int sock_soc_get_state_result_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1767 | {
|
| 1768 | sk_soc_info("sock_soc_find_other_result_proc");
|
| 1769 | sock_soc_rsp_proc(psock_rpmsg);
|
| 1770 | return 0;
|
| 1771 | }
|
| 1772 |
|
| 1773 | int sock_soc_test_flags(struct sock *other, enum sock_flags flag)
|
| 1774 | {
|
| 1775 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1776 | struct ipc_socket * ipcsocket;
|
| 1777 | struct sock_rpmsg_info *psock_rpmsg_info;
|
| 1778 | int result;
|
| 1779 | sock_rpmsg.msg_type = MSG_TYPE_TEST_FLAG;
|
| 1780 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1781 | if(ipcsocket == NULL){
|
| 1782 | sk_soc_info("sock_soc_test_flags failed, other->fd=%d\n ", other->sk_fd);
|
| 1783 | return -1;
|
| 1784 | }
|
| 1785 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1786 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1787 | sock_rpmsg.clientsock = ipcsocket->localsocket;
|
| 1788 | //sock_rpmsg.flag = flag;
|
| 1789 | sock_rpmsg.flag = convert_to_cap_sock_flag(flag);
|
| 1790 | if(sock_rpmsg.flag == -1)
|
| 1791 | {
|
| 1792 | sk_soc_info("cap do not support flag=%s ", flag_value[flag]);
|
| 1793 | return 0;
|
| 1794 | }
|
| 1795 | sock_rpmsg.key = other;
|
| 1796 | sk_soc_info("sock_soc_test_flags serverfd=%d", sock_rpmsg.serverfd);
|
| 1797 |
|
| 1798 | psock_rpmsg_info = sock_soc_create_rpmsg_info(sock_rpmsg.key);
|
| 1799 | if(NULL == psock_rpmsg_info){
|
| 1800 | sk_soc_info("sock_soc_get_state create rpmsg faild \n");
|
| 1801 | return -1;
|
| 1802 | }
|
| 1803 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1804 | down_timeout(&psock_rpmsg_info->sock_sem, msecs_to_jiffies(g_sock_timeout));
|
| 1805 | sk_soc_info("sock_soc_test_flags flag=%s, result=%d\n",flag_value[flag], g_sock_rpmsg.result);
|
| 1806 | result = psock_rpmsg_info->sock_rpmsg.result;
|
| 1807 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 1808 | return result;
|
| 1809 | }
|
| 1810 | EXPORT_SYMBOL_GPL(sock_soc_test_flags);
|
| 1811 |
|
| 1812 | int sock_soc_test_flags_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1813 | {
|
| 1814 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1815 | struct socket* socket;
|
| 1816 | struct sock *other;
|
| 1817 | int err;
|
| 1818 | //socket = sock_get_local_socket(psock_rpmsg->serverfd, &err);
|
| 1819 | sock_rpmsg.msg_type = MSG_TYPE_TEST_FLAG_RESULT;
|
| 1820 | sock_rpmsg.key = psock_rpmsg->key;
|
| 1821 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1822 | if(sock_soc_socket_is_valid_ipc(socket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1823 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1824 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1825 | return -1;
|
| 1826 | }
|
| 1827 | if(NULL == socket){
|
| 1828 | sk_soc_info("sock_soc_test_flags_proc failed, flag=%s", flag_value[psock_rpmsg->flag]);
|
| 1829 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1830 | return -1;
|
| 1831 | }
|
| 1832 | other = socket->sk;
|
| 1833 | if(other == NULL){
|
| 1834 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1835 | return -1;
|
| 1836 | }
|
| 1837 | sock_rpmsg.result = test_bit(psock_rpmsg->flag, &other->sk_flags);
|
| 1838 | sk_soc_info("sock_soc_test_flags_proc flag=%s, result=%d", flag_value[psock_rpmsg->flag], sock_rpmsg.result);
|
| 1839 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1840 | return 0;
|
| 1841 | }
|
| 1842 |
|
| 1843 | int sock_soc_test_flags_result_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1844 | {
|
| 1845 | sk_soc_info("sock_soc_test_flags_result_proc enter");
|
| 1846 | sock_soc_rsp_proc(psock_rpmsg);
|
| 1847 |
|
| 1848 | return 0;
|
| 1849 | }
|
| 1850 |
|
| 1851 | void sock_soc_add_skb_queue_tail(struct sock *sock, struct sock *other)
|
| 1852 | {
|
| 1853 | struct ipc_socket * ipcsocket;
|
| 1854 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1855 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 1856 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 1857 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1858 | if(ipcsocket == NULL){
|
| 1859 | sk_soc_info("sock_soc_add_skb_queue_tail failed, other->fd=%d\n ", other->sk_fd);
|
| 1860 | return;
|
| 1861 | }
|
| 1862 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1863 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1864 | sock_rpmsg.clientsock = ipcsocket->localsocket;
|
| 1865 | sock_rpmsg.msg_type = MSG_TYPE_ADD_SKB_QUEUE_TAIL;
|
| 1866 | sk_soc_info("sock_soc_add_skb_queue_tail clientfd=%d, serverfd=%d", sock_rpmsg.clientfd, sock_rpmsg.serverfd);
|
| 1867 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1868 | }
|
| 1869 |
|
| 1870 | void sock_soc_add_skb_queue_tail_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1871 | {
|
| 1872 | struct ipc_socket * ipcsocket;
|
| 1873 | struct socket* other;
|
| 1874 | struct sk_buff *skb = NULL;
|
| 1875 | int err;
|
| 1876 | //¸ù¾ÝclientfdÕÒµ½±¾µØ´úÀísocket
|
| 1877 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1878 | if(ipcsocket == NULL){
|
| 1879 | sk_soc_info("sock_soc_add_skb_queue_tail_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1880 | return;
|
| 1881 | }
|
| 1882 | //other = sockfd_lookup(psock_rpmsg->serverfd, &err);
|
| 1883 | other = (struct socket*)psock_rpmsg->serversock;
|
| 1884 | if(sock_soc_socket_is_valid_ipc(other, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 1885 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 1886 | return;
|
| 1887 | }
|
| 1888 | sk_soc_info("sock_soc_add_skb_queue_tail clientfd=%d, serverfd=%d", psock_rpmsg->clientfd, psock_rpmsg->serverfd);
|
| 1889 | if((NULL != ipcsocket) && (NULL != other)){
|
| 1890 | /* Allocate skb for sending to listening sock */
|
| 1891 | skb = sock_wmalloc(ipcsocket->sock, 1, 0, GFP_KERNEL);
|
| 1892 | if (skb == NULL)
|
| 1893 | {
|
| 1894 | return;
|
| 1895 | }
|
| 1896 |
|
| 1897 | __skb_queue_tail(&other->sk->sk_receive_queue, skb);
|
| 1898 | sk_soc_info("sock_soc_add_skb_queue_tail sucess! \n");
|
| 1899 | }
|
| 1900 | }
|
| 1901 |
|
| 1902 | void sock_soc_stream_connect(struct sock *sock, struct sock *other, struct sockaddr_un *sunname, int len,int flags)
|
| 1903 | {
|
| 1904 | struct ipc_socket * ipcsocket;
|
| 1905 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1906 | struct sock_rpmsg_info *psock_rpmsg_info;
|
| 1907 | if(len > 0){
|
| 1908 | memcpy(&sock_rpmsg.sockaddr, sunname, sizeof(struct sockaddr_un));
|
| 1909 | sk_soc_info("sock_soc_stream_connect sockaddr=%s", sock_rpmsg.sockaddr.sun_path);
|
| 1910 | sock_rpmsg.addr_len = len;
|
| 1911 | }
|
| 1912 | sock_rpmsg.flags = flags;
|
| 1913 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 1914 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 1915 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1916 | if(ipcsocket == NULL){
|
| 1917 | sk_soc_info("sock_soc_stream_connect failed, other->fd=%d\n ", other->sk_fd);
|
| 1918 | return;
|
| 1919 | }
|
| 1920 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1921 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1922 | sock_rpmsg.msg_type = MSG_TYPE_STREAM_CONNECT;
|
| 1923 | sock_rpmsg.key = sock_rpmsg.clientsock;
|
| 1924 | psock_rpmsg_info = sock_soc_create_rpmsg_info(sock_rpmsg.key);
|
| 1925 | if(NULL == psock_rpmsg_info){
|
| 1926 | sk_soc_info("sock_soc_stream_connect create rpmsg faild \n");
|
| 1927 | return;
|
| 1928 | }
|
| 1929 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1930 | //ÒªµÈµ½ÊÕµ½update_peer²ÅÄÜ·µ»Ø
|
| 1931 | down_timeout(&psock_rpmsg_info->sock_sem, msecs_to_jiffies(g_sock_timeout));
|
| 1932 | sk_soc_info("sock_soc_stream_connect clientfd=%d, serverfd=%d\n", sock_rpmsg.clientfd, sock_rpmsg.serverfd);
|
| 1933 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 1934 | }
|
| 1935 |
|
| 1936 | void sock_soc_stream_connect_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1937 | {
|
| 1938 | struct ipc_socket * ipcsocket;
|
| 1939 | struct socket* other;
|
| 1940 | struct sk_buff *skb = NULL;
|
| 1941 | struct sock *newsk = NULL;
|
| 1942 | int result = -1;
|
| 1943 | int err;
|
| 1944 | //¸ù¾ÝclientfdÕÒµ½±¾µØ´úÀísocket
|
| 1945 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1946 | if(ipcsocket == NULL){
|
| 1947 | sk_soc_info("sock_soc_stream_connect_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1948 | return;
|
| 1949 | }
|
| 1950 | //other = sockfd_lookup(psock_rpmsg->serverfd, &err);
|
| 1951 | other = (struct socket*)psock_rpmsg->serversock;
|
| 1952 |
|
| 1953 | sk_soc_info("sock_soc_stream_connect_proc clientfd=%d, serverfd=%d\n", psock_rpmsg->clientfd, psock_rpmsg->serverfd);
|
| 1954 | if((NULL != ipcsocket) && (NULL != other)){
|
| 1955 | sk_soc_info("sockaddr=%s", psock_rpmsg->sockaddr.sun_path);
|
| 1956 | result = unix_stream_connect_proxy(ipcsocket->socket, (struct sockaddr *)&psock_rpmsg->sockaddr, psock_rpmsg->addr_len, psock_rpmsg->flags);
|
| 1957 | if(0 == result){
|
| 1958 | sk_soc_info("sock_soc_stream_connect_proc sucess! ");
|
| 1959 | }else{
|
| 1960 | sk_soc_info("sock_soc_stream_connect_proc failed! ");
|
| 1961 | }
|
| 1962 | }
|
| 1963 | }
|
| 1964 |
|
| 1965 | void sock_soc_add_wait_queue(struct sock *sock, struct sock *other)
|
| 1966 | {
|
| 1967 | struct ipc_socket * ipcsocket;
|
| 1968 | struct sock_rpmsg sock_rpmsg = {0};
|
| 1969 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 1970 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 1971 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 1972 | if(ipcsocket == NULL){
|
| 1973 | sk_soc_info("sock_soc_add_wait_queue failed, other->fd=%d\n ", other->sk_fd);
|
| 1974 | return;
|
| 1975 | }
|
| 1976 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 1977 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 1978 | sock_rpmsg.msg_type = MSG_TYPE_ADD_WAIT_QUEUE;
|
| 1979 | sk_soc_info("sock_soc_add_wait_queue enter");
|
| 1980 | sock_send_ipc_msg(&sock_rpmsg);
|
| 1981 | }
|
| 1982 |
|
| 1983 | void sock_soc_add_wait_queue_proc(struct sock_rpmsg* psock_rpmsg)
|
| 1984 | {
|
| 1985 | struct ipc_socket * ipcsocket;
|
| 1986 | struct socket* socket;
|
| 1987 | int err;
|
| 1988 | //¸ù¾ÝclientfdÕÒµ½±¾µØ´úÀísocket
|
| 1989 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 1990 | if(ipcsocket == NULL){
|
| 1991 | sk_soc_info("sock_soc_add_wait_queue_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 1992 | return;
|
| 1993 | }
|
| 1994 | //socket = sockfd_lookup(psock_rpmsg->serverfd, &err);
|
| 1995 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 1996 |
|
| 1997 | sk_soc_info("sock_soc_add_wait_queue_proc clientfd=%d, serverfd=%d", psock_rpmsg->clientfd, psock_rpmsg->serverfd);
|
| 1998 | if((NULL != ipcsocket) && (NULL != socket)){
|
| 1999 | unix_dgram_peer_wake_connect_proxy(ipcsocket->sock, socket->sk);
|
| 2000 | }
|
| 2001 | }
|
| 2002 |
|
| 2003 | void sock_soc_remove_wait_queue(struct sock *sock, struct sock *other)
|
| 2004 | {
|
| 2005 | struct ipc_socket * ipcsocket;
|
| 2006 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2007 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 2008 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 2009 | ipcsocket = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 2010 | if(ipcsocket == NULL){
|
| 2011 | sk_soc_info("sock_soc_remove_wait_queue failed, other->fd=%d\n ", other->sk_fd);
|
| 2012 | return;
|
| 2013 | }
|
| 2014 | sock_rpmsg.serverfd = ipcsocket->remotefd;
|
| 2015 | sock_rpmsg.serversock = ipcsocket->remotesocket;
|
| 2016 | sock_rpmsg.msg_type = MSG_TYPE_REMOVE_WAIT_QUEUE;
|
| 2017 | sk_soc_info("sock_soc_remove_wait_queue clientfd=%d, serverfd=%d", sock_rpmsg.clientfd, sock_rpmsg.serverfd);
|
| 2018 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2019 | }
|
| 2020 |
|
| 2021 | void sock_soc_remove_wait_queue_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2022 | {
|
| 2023 | struct ipc_socket * ipcsocket;
|
| 2024 | struct socket* socket;
|
| 2025 | int err;
|
| 2026 | //¸ù¾ÝclientfdÕÒµ½±¾µØ´úÀísocket
|
| 2027 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 2028 | if(ipcsocket == NULL){
|
| 2029 | sk_soc_info("sock_soc_remove_wait_queue_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 2030 | return;
|
| 2031 | }
|
| 2032 | //socket = sockfd_lookup(psock_rpmsg->serverfd, &err);
|
| 2033 | socket = (struct socket*)psock_rpmsg->serversock;
|
| 2034 |
|
| 2035 | sk_soc_info("sock_soc_remove_wait_queue_proc clientfd=%d, serverfd=%d", psock_rpmsg->clientfd, psock_rpmsg->serverfd);
|
| 2036 | if((NULL != ipcsocket) && (NULL != socket)){
|
| 2037 | unix_dgram_peer_wake_connect_proxy(ipcsocket->sock, socket->sk);
|
| 2038 | }
|
| 2039 | }
|
| 2040 |
|
| 2041 | void sock_soc_notify_proxy_change_to_server(struct socket* proxysocket, struct socket* remoteproxysocket)
|
| 2042 | {
|
| 2043 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2044 | sock_rpmsg.clientproxyfd = proxysocket->fd;
|
| 2045 | sock_rpmsg.clientproxysock = proxysocket;
|
| 2046 | sock_rpmsg.serverproxysock = remoteproxysocket;
|
| 2047 | sock_rpmsg.msg_type = MSG_TYPE_NOTIFY_PROXY_CHANGE;
|
| 2048 | sk_soc_info("sock_soc_notify_proxy_change_to_server clientproxysock=%x, serverproxysock=%x", sock_rpmsg.clientproxysock, sock_rpmsg.serverproxysock);
|
| 2049 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2050 | }
|
| 2051 |
|
| 2052 | void sock_soc_notify_proxy_change_to_server_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2053 | {
|
| 2054 | struct ipc_socket* ipc_socket;
|
| 2055 | struct socket* serverproxysock;
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2056 | serverproxysock = (struct socket*)psock_rpmsg->serverproxysock;
|
| 2057 | ipc_socket = sock_soc_get_ipcsocket_by_proxysock(serverproxysock->sk);
|
| 2058 | sk_soc_info("sock_soc_notify_proxy_change_to_server_proc serverproxysock=%x", psock_rpmsg->serverproxysock);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2059 | if(NULL != ipc_socket){
|
| 2060 | sk_soc_info("sock_soc_notify_proxy_change_to_server_proc remoteproxysocket=%x", psock_rpmsg->clientproxysock);
|
| 2061 | ipc_socket->remoteproxyfd = psock_rpmsg->clientproxyfd;
|
| 2062 | ipc_socket->remoteproxysocket = psock_rpmsg->clientproxysock;
|
| 2063 | serverproxysock = (struct socket*)psock_rpmsg->serverproxysock;
|
| 2064 | usock_update_remote_proxy_socket(serverproxysock->sk, psock_rpmsg->clientproxysock);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2065 | }else{
|
| 2066 | sk_soc_info("sock_soc_notify_proxy_change_to_server_proc ipc_socket is NULL");
|
| 2067 | }
|
| 2068 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2069 | }
|
| 2070 |
|
| 2071 | struct sock *sock_soc_find_other(struct socket * socket/*int fd*/,
|
| 2072 | struct sockaddr_un *sunname, int len,
|
| 2073 | int type, unsigned int hash, int *error)
|
| 2074 | {
|
| 2075 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2076 | struct ipc_socket *psocket_ipc = NULL;
|
| 2077 | struct sock_rpmsg_info *psock_rpmsg_info = NULL;
|
| 2078 | int err;
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2079 |
|
| 2080 | if(0 == socket_rpmsg_enable){
|
| 2081 | return NULL;
|
| 2082 | }
|
| 2083 |
|
| 2084 | if(false == sock_soc_ipc_sunaddr_exist(sunname)){
|
| 2085 | sk_soc_info("sock_soc_ipc_sunaddr_exist is false, sunname=%s", sunname->sun_path);
|
| 2086 | return NULL;
|
| 2087 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2088 | //struct socket *clisocket = sock_get_local_socket(fd, &err);
|
| 2089 | memcpy(&sock_rpmsg.sockaddr, sunname, sizeof(struct sockaddr_un));
|
| 2090 | sock_rpmsg.addr_len = len;
|
| 2091 | sock_rpmsg.socktype = type;
|
| 2092 | sock_rpmsg.hash = hash;
|
| 2093 | sock_rpmsg.clientfd = socket->fd;
|
| 2094 | sock_rpmsg.clientsock = socket;
|
| 2095 | sock_rpmsg.key = socket;
|
| 2096 | sock_rpmsg.msg_type = MSG_TYPE_FIND;
|
| 2097 | sock_rpmsg.isfistfind = 0;
|
| 2098 |
|
| 2099 | if(sock_soc_get_ipcsocket_by_localsocket(socket) == NULL){ //˵Ã÷ÊǵÚÒ»´Î·¢Æð²éÕÒ
|
| 2100 | sock_rpmsg.isfistfind = 1;
|
| 2101 | }
|
| 2102 |
|
| 2103 | psock_rpmsg_info = sock_soc_create_rpmsg_info(sock_rpmsg.key);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2104 | if(NULL == psock_rpmsg_info){
|
| 2105 | sk_soc_info("sock_soc_find_other create rpmsg faild \n");
|
| 2106 | return NULL;
|
| 2107 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2108 | sk_soc_info("sock_soc_find_other clientfd=%d, key=%x", sock_rpmsg.clientfd, sock_rpmsg.key);
|
| 2109 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2110 | down_timeout(&psock_rpmsg_info->sock_sem, msecs_to_jiffies(g_sock_timeout));
|
| 2111 |
|
| 2112 | if(test_bit(SOCK_OP_RESULT, &psock_rpmsg_info->sock_rpmsg.flags)){
|
| 2113 | sk_soc_info("sock_soc_find_other sucess serverfd=%d", psock_rpmsg_info->sock_rpmsg.serverfd);
|
| 2114 | psocket_ipc = psock_rpmsg_info->ipc_socket;
|
| 2115 | sk_soc_info("sock_soc_find_other sockfd=%d, remotefd=%d", psocket_ipc->sockfd, psocket_ipc->remotefd);
|
| 2116 | //socket->peer = psocket_ipc->socket;
|
| 2117 | sock_soc_insert_socket_peer(socket, psocket_ipc->proxysocket);
|
| 2118 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 2119 | sock_soc_notify_proxy_change_to_server(psocket_ipc->proxysocket, psocket_ipc->remoteproxysocket);
|
| 2120 | //sock_soc_set_socket_info(psocket_ipc->socket, socket);
|
| 2121 | return psocket_ipc->sock;
|
| 2122 | } else {
|
| 2123 | sk_soc_info("sock_soc_find_other failed, no matched socket");
|
| 2124 | }
|
| 2125 | sock_soc_del_rpmsg_info(sock_rpmsg.key);
|
| 2126 |
|
| 2127 | return NULL;
|
| 2128 | }
|
| 2129 |
|
| 2130 | int sock_soc_find_other_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2131 | {
|
| 2132 | struct sock *u;
|
| 2133 | struct ipc_socket *psocket_ipc = NULL;
|
| 2134 | //struct net tmpnet={0};
|
| 2135 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2136 | int serverfd;
|
| 2137 | int error = -1;
|
| 2138 | unsigned int hash;
|
| 2139 | sk_soc_info("sock_soc_find_other_proc index=%d", psock_rpmsg->index);
|
| 2140 | if((NULL == psock_rpmsg) || (psock_rpmsg->msg_type != MSG_TYPE_FIND)){
|
| 2141 | sk_soc_info("sock_soc_find_other_proc failed, NULL == psock_rpmsg");
|
| 2142 | return -1;
|
| 2143 | }
|
| 2144 | sock_rpmsg.msg_type = MSG_TYPE_FIND_RESULT;
|
| 2145 | sk_soc_info("sockaddr=%s,socktype=%d, hash=%d",psock_rpmsg->sockaddr.sun_path,psock_rpmsg->socktype,psock_rpmsg->hash);
|
| 2146 | error = unix_mkname_proxy(&psock_rpmsg->sockaddr, psock_rpmsg->addr_len, &hash);
|
| 2147 | if (error < 0){
|
| 2148 | sk_soc_info("unix_mkname_proxy failed, error=%d", error);
|
| 2149 | }
|
| 2150 | sk_soc_info("unix_mkname_proxy sucess, hash=%d", hash);
|
| 2151 | //init_net
|
| 2152 | u = unix_find_other_proxy(&init_net, &psock_rpmsg->sockaddr, psock_rpmsg->addr_len, psock_rpmsg->socktype, hash, &error);
|
| 2153 | if(u){
|
| 2154 | sk_soc_info("find_other_proc: u(%x)->sk_socket=%x\n", u, u->sk_socket);
|
| 2155 | serverfd = sock_lookup_fd_by_sock(u);
|
| 2156 | psock_rpmsg->serverfd = serverfd;
|
| 2157 | psock_rpmsg->serversock = u->sk_socket;
|
| 2158 | psocket_ipc = sock_create_proxy_socket_client(psock_rpmsg);
|
| 2159 | if(NULL != psocket_ipc){
|
| 2160 | psocket_ipc->localsocket = u->sk_socket;
|
| 2161 | set_bit(SOCK_OP_RESULT, &sock_rpmsg.flags);
|
| 2162 | //memcpy(&sock_rpmsg.sock, u, sizeof(struct sock));
|
| 2163 | sock_rpmsg.serverfd = serverfd;
|
| 2164 | sock_rpmsg.serversock = u->sk_socket;
|
| 2165 | sock_rpmsg.socktype = u->sk_socket->type;
|
| 2166 | sock_rpmsg.serverproxyfd = psocket_ipc->sockfd;
|
| 2167 | sock_rpmsg.serverproxysock = psocket_ipc->proxysocket;
|
| 2168 | //u->sk_socket->peer = psocket_ipc->socket; //TODO:u¿ÉÄܱ»¶à¸ö¿Í»§¶Ë²éÕÒ£¬´Ë´¦peerÖ¸Ïò´úÀísocketÓÐÎÊÌ⣬ÒòΪ¿ÉÄÜ´æÔÚ¶à¸ö´úÀísocket
|
| 2169 | sock_soc_insert_socket_peer(u->sk_socket, psocket_ipc->proxysocket);
|
| 2170 | }
|
| 2171 |
|
| 2172 | sock_put(u); //0707
|
| 2173 | sk_soc_info("sock_soc_find_other_proc success, socktype=%d, serverfd=%d, key=%x, index=%d\n", sock_rpmsg.socktype, sock_rpmsg.serverfd, psock_rpmsg->key, psock_rpmsg->index);
|
| 2174 | }
|
| 2175 | else
|
| 2176 | {
|
| 2177 | sk_soc_info("sock_soc_find_other_proc failed, error=%d", error);
|
| 2178 | }
|
| 2179 | sock_rpmsg.key = psock_rpmsg->key;
|
| 2180 | sock_rpmsg.clientfd = psock_rpmsg->clientfd;
|
| 2181 | sock_rpmsg.clientsock = psock_rpmsg->clientsock;
|
| 2182 | sock_rpmsg.index = psock_rpmsg->index;
|
| 2183 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2184 |
|
| 2185 | return 0;
|
| 2186 | }
|
| 2187 |
|
| 2188 | int sock_soc_find_other_result_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2189 | {
|
| 2190 | struct sock_rpmsg_info *psock_rpmsg_info = NULL;
|
| 2191 |
|
| 2192 | psock_rpmsg_info = sock_soc_get_rpmsg_info(psock_rpmsg->key);
|
| 2193 | if(NULL == psock_rpmsg_info){
|
| 2194 | sk_soc_info("sock_soc_find_other_result_proc failed\n");
|
| 2195 | return -1;
|
| 2196 | }
|
| 2197 | memset(&psock_rpmsg_info->sock_rpmsg, 0, sizeof(struct sock_rpmsg));
|
| 2198 | memcpy(&psock_rpmsg_info->sock_rpmsg, psock_rpmsg, sizeof(struct sock_rpmsg));
|
| 2199 | if(test_bit(SOCK_OP_RESULT, &psock_rpmsg->flags)){
|
| 2200 | psock_rpmsg_info->ipc_socket = sock_create_proxy_socket_server(psock_rpmsg);
|
| 2201 | }
|
| 2202 | up(&psock_rpmsg_info->sock_sem);
|
| 2203 | return 0;
|
| 2204 | }
|
| 2205 |
|
| 2206 | static void delayed_release(struct work_struct *unused)
|
| 2207 | {
|
| 2208 | //struct llist_node *node = llist_del_all(&delayed_release_list);
|
| 2209 | struct release_socket *rsock, *t;
|
| 2210 | sk_soc_info("delayed_release enter\n");
|
| 2211 | spin_lock(&sock_release_table_lock);
|
| 2212 | list_for_each_entry_safe(rsock, t, &delayed_release_list, list_node){
|
| 2213 | //sock_soc_release_sock(rsock);
|
| 2214 | sock_soc_release_peer(rsock);
|
| 2215 | list_del(&rsock->list_node);
|
| 2216 | kfree(rsock);
|
| 2217 | }
|
| 2218 | spin_unlock(&sock_release_table_lock);
|
| 2219 | }
|
| 2220 |
|
| 2221 | static DECLARE_DELAYED_WORK(delayed_release_work, delayed_release);
|
| 2222 |
|
| 2223 | void sock_soc_delay_release(struct socket *sock)
|
| 2224 | {
|
| 2225 | struct release_socket* prelease_socket = NULL;
|
| 2226 | struct unix_sock* usock;
|
| 2227 | struct socket_info *p;
|
| 2228 | struct hlist_node *pos,*n;
|
| 2229 | if(!hlist_empty(&sock->peer)){
|
| 2230 | spin_lock(&sock_release_peer_lock);
|
| 2231 | hlist_for_each_entry_safe(p, pos, n, &sock->peer, hlist_node) {
|
| 2232 | usock = unix_sk(p->proxysocket->sk);
|
| 2233 | //ÅжÏusockÐÅÏ¢ÊÇ·ñ»¹ÔÚ´úÀíÁ´±íÖÐ
|
| 2234 | if(0 != sock_is_valide_ipc_socket(usock->rsock.localsocket, usock->rsock.proxysocket, usock->rsock.remotesocket)){
|
| 2235 | sk_soc_info("sock_soc_delay_release failed \n");
|
| 2236 | continue;
|
| 2237 | }
|
| 2238 | prelease_socket = (struct release_socket *)kzalloc(sizeof(struct release_socket), GFP_ATOMIC);
|
| 2239 | if(NULL == prelease_socket){
|
| 2240 | sk_soc_info("kzalloc failed \n");
|
| 2241 | continue;
|
| 2242 | }
|
| 2243 | memcpy(prelease_socket, &usock->rsock, sizeof(struct release_socket));
|
| 2244 | list_add(&prelease_socket->list_node, &delayed_release_list);
|
| 2245 | sock_soc_del_socket_info(p->proxysocket, sock);
|
| 2246 | }
|
| 2247 |
|
| 2248 | //sock_put(sock->sk); /* It may now die */
|
| 2249 |
|
| 2250 | INIT_HLIST_HEAD(&sock->peer);
|
| 2251 | spin_unlock(&sock_release_peer_lock);
|
| 2252 | schedule_delayed_work(&delayed_release_work, 1);
|
| 2253 | //}
|
| 2254 | }
|
| 2255 |
|
| 2256 | }
|
| 2257 |
|
| 2258 | int sock_soc_release_peer(struct release_socket* rsock)
|
| 2259 | {
|
| 2260 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2261 | struct socket* peersocket;
|
| 2262 | struct ipc_socket * ipcsocket;
|
| 2263 | struct sock* proxy_sock = NULL;
|
| 2264 | //ɾ³ý±¾µØ¶ÔÓ¦µÄ´úÀísocket
|
| 2265 | if(rsock->proxysocket){
|
| 2266 | sk_soc_info("sock_soc_release_peer close fd=%d \n", rsock->proxysocket->fd);
|
| 2267 | sock_rpmsg.socktype = rsock->proxysocket->type;
|
| 2268 | //ipcsocket = sock_soc_get_ipcsocket(rsock->sock->sk); //0706¸ù¾Ý±¾µØ´úÀísocket,ÕÒµ½¶ÔÓ¦·þÎñ¶Ësocket
|
| 2269 | if(NULL != rsock->remotesocket){
|
| 2270 | sock_rpmsg.serverfd = rsock->remotefd;
|
| 2271 | sock_rpmsg.serversock = rsock->remotesocket;
|
| 2272 | }else{
|
| 2273 | sk_soc_info("sock_soc_get_ipcsocket_by_proxysock failed \n");
|
| 2274 | }
|
| 2275 |
|
| 2276 | spin_lock(&sock_release_lock);
|
| 2277 |
|
| 2278 | rsock->proxysocket->sk->closed = 1;
|
| 2279 | proxy_sock = rsock->proxysocket->sk->proxy_sock;
|
| 2280 | sys_close(rsock->proxysocket->fd);
|
| 2281 | if(proxy_sock != NULL){ //0706
|
| 2282 | unix_release_sock_proxy(proxy_sock);
|
| 2283 | }
|
| 2284 | //Ç°ÃæÒѾɾ³ý¹ýÁË
|
| 2285 | //sock_del_ipc_socket_by_proxysocket(rsock->proxysocket);
|
| 2286 | spin_unlock(&sock_release_lock);
|
| 2287 | }
|
| 2288 | sock_rpmsg.clientfd = rsock->localfd;
|
| 2289 | sock_rpmsg.clientsock = rsock->localsocket;
|
| 2290 | sock_rpmsg.serversock = rsock->remotesocket;
|
| 2291 | sock_rpmsg.serverproxysock = rsock->remoteproxysocket;
|
| 2292 | sock_rpmsg.msg_type = MSG_TYPE_RELEASE_PEER;
|
| 2293 | sk_soc_info("sock_soc_release_peer clientfd=%d \n", sock_rpmsg.clientfd);
|
| 2294 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2295 | return 0;
|
| 2296 | }
|
| 2297 |
|
| 2298 | int sock_soc_release_peer_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2299 | {
|
| 2300 | struct ipc_socket * ipcsocket;
|
| 2301 | struct socket* proxysocket;
|
| 2302 | struct socket* serversocket;
|
| 2303 | struct sock* skpair;
|
| 2304 | int type;
|
| 2305 | int closefd;
|
| 2306 | int err;
|
| 2307 | sk_soc_info("sock_soc_release_peer_proc clientfd=%d \n", psock_rpmsg->clientfd);
|
| 2308 | //¸ù¾ÝclientfdÕÒµ½±¾µØ´úÀísocket
|
| 2309 | spin_lock(&sock_release_lock);
|
| 2310 | //ÅжÏsocketÐÅÏ¢ÊÇ·ñ»¹ÔÚ´úÀíÁ´±íÖÐ
|
| 2311 | if(0 != sock_is_valide_ipc_socket(psock_rpmsg->serversock, psock_rpmsg->serverproxysock, psock_rpmsg->clientsock)){
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2312 | spin_unlock(&sock_release_lock);
|
xf.li | 7ccf837 | 2024-03-07 00:08:02 -0800 | [diff] [blame] | 2313 | sk_soc_info("sock_soc_release_peer_proc failed, sock_is_valide_ipc_socket=false \n");
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2314 | return -1;
|
| 2315 | }
|
| 2316 |
|
| 2317 | ipcsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 2318 | if(ipcsocket != NULL){
|
| 2319 | type = psock_rpmsg->socktype;
|
| 2320 | sk_soc_info("sock_soc_release_peer_proc close sockfd=%d, socktype=%d\n", ipcsocket->sockfd, type);
|
| 2321 | //sock_soc_del_socket_info(ipcsocket->socket, ipcsocket->localsocket); //0706 ½«´úÀísocket´ÓsocketsÁбíÖÐɾ³ý
|
| 2322 |
|
| 2323 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 2324 | proxysocket = (struct socket*)ipcsocket->proxysocket;
|
| 2325 | //ĿǰSOCK_STREAMºÍSOCK_DGRAMÊÍ·ÅÁ÷³ÌÓÐÇø±ð
|
| 2326 | if(type == SOCK_STREAM){
|
| 2327 | //sock_del_ipc_socket_by_socket(ipcsocket->proxysocket);
|
| 2328 | skpair = serversocket->sk;
|
| 2329 | unix_state_lock(skpair);
|
| 2330 | /* No more writes */
|
| 2331 | skpair->sk_shutdown = SHUTDOWN_MASK;
|
| 2332 | //if (!skb_queue_empty(&sk->sk_receive_queue) || embrion)
|
| 2333 | // serversocket->sk_err = ECONNRESET;
|
| 2334 | unix_state_unlock(skpair);
|
| 2335 | skpair->sk_state_change(skpair);
|
| 2336 | sk_wake_async(skpair, SOCK_WAKE_WAITD, POLL_HUP);
|
| 2337 | }else if(type == SOCK_DGRAM){
|
| 2338 |
|
| 2339 | sock_soc_del_socket_peer(serversocket, proxysocket);
|
| 2340 | ipcsocket->sock->closed = 1;
|
| 2341 | closefd = ipcsocket->sockfd;
|
| 2342 | sock_soc_del_socket_info(ipcsocket->socket, ipcsocket->localsocket); //0706 ½«´úÀísocket´ÓsocketsÁбíÖÐɾ³ý
|
| 2343 |
|
| 2344 | sys_close(closefd);
|
| 2345 | }
|
| 2346 | }else{
|
| 2347 | sk_soc_info("sock_soc_release_peer_proc failed, localsock=%x, remotesock=%x", psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 2348 |
|
| 2349 | }
|
| 2350 | spin_unlock(&sock_release_lock);
|
| 2351 | return 0;
|
| 2352 | }
|
| 2353 |
|
| 2354 | int sock_soc_dgram_disconnected(struct sock *sock, struct sock *other)
|
| 2355 | {
|
| 2356 | struct ipc_socket *psocket_ipc = NULL;
|
| 2357 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2358 | sock_rpmsg.msg_type = MSG_TYPE_DGRAM_DISCONNECTED;
|
| 2359 |
|
| 2360 | //¿Í»§¶Ësocket fd
|
| 2361 | sock_rpmsg.clientfd = sock_lookup_fd_by_sock(sock);
|
| 2362 | sock_rpmsg.clientsock = sock->sk_socket;
|
| 2363 | //²éÕÒ·þÎñÆ÷¶Ë´úÀísocketÏà¹ØÐÅÏ¢
|
| 2364 | psocket_ipc = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 2365 | if(psocket_ipc == NULL){
|
| 2366 | sk_soc_info("sock_soc_remove_wait_queue failed, other->fd=%d\n ", other->sk_fd);
|
| 2367 | return -1;
|
| 2368 | }
|
| 2369 | //·þÎñÆ÷¶Ësocket fd
|
| 2370 | sock_rpmsg.serverfd = psocket_ipc->remotefd;
|
| 2371 | sock_rpmsg.serversock = psocket_ipc->remotesocket;
|
| 2372 | sk_soc_info("sock_soc_dgram_disconnected clientfd=%d, serverfd=%d \n", sock_rpmsg.clientfd, sock_rpmsg.serverfd);
|
| 2373 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2374 | return 0;
|
| 2375 | }
|
| 2376 |
|
| 2377 | int sock_soc_dgram_disconnected_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2378 | {
|
| 2379 | struct ipc_socket* clientsocket;
|
| 2380 | struct socket* serversocket;
|
| 2381 | struct sock* sock;
|
| 2382 | struct sock* other;
|
| 2383 |
|
| 2384 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 2385 | if(sock_soc_socket_is_valid_ipc(serversocket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 2386 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 2387 | return -1;
|
| 2388 | }
|
| 2389 | other = serversocket->sk;
|
| 2390 |
|
| 2391 | clientsocket = sock_get_ipcsocket_by_local_and_remote(psock_rpmsg->serversock, psock_rpmsg->clientsock);
|
| 2392 | if(clientsocket == NULL){
|
| 2393 | sk_soc_info("sock_soc_dgram_disconnected_proc failed, clientfd=%d,clientsock=%x\n ", psock_rpmsg->clientfd, psock_rpmsg->clientsock);
|
| 2394 | return -1;
|
| 2395 | }
|
| 2396 | sock = clientsocket->sock;
|
| 2397 |
|
| 2398 | sk_soc_info("sock_soc_dgram_disconnected_proc clientfd=%d, serverfd=%d \n", psock_rpmsg->clientfd, psock_rpmsg->serverfd);
|
| 2399 | unix_dgram_disconnected_proxy(sock, other);
|
| 2400 | return 0;
|
| 2401 | }
|
| 2402 |
|
| 2403 | void sock_soc_state_lock(struct sock *other)
|
| 2404 | {
|
| 2405 | struct ipc_socket *psocket_ipc = NULL;
|
| 2406 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2407 | sock_rpmsg.msg_type = MSG_TYPE_STATE_LOCK;
|
| 2408 |
|
| 2409 | //²éÕÒ·þÎñÆ÷¶Ë´úÀísocketÏà¹ØÐÅÏ¢
|
| 2410 | psocket_ipc = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 2411 | if(psocket_ipc == NULL){
|
| 2412 | sk_soc_info("sock_soc_state_lock failed, other->fd=%d\n ", other->sk_fd);
|
| 2413 | return;
|
| 2414 | }
|
| 2415 | //·þÎñÆ÷¶Ësocket fd
|
| 2416 | sock_rpmsg.serverfd = psocket_ipc->remotefd;
|
| 2417 | sock_rpmsg.serversock = psocket_ipc->remotesocket;
|
| 2418 | sock_rpmsg.clientsock = psocket_ipc->localsocket;
|
| 2419 | sk_soc_info("sock_soc_state_lock serverfd=%d \n", sock_rpmsg.serverfd);
|
| 2420 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2421 | }
|
| 2422 |
|
| 2423 | int sock_soc_state_lock_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2424 | {
|
| 2425 | struct socket* serversocket;
|
| 2426 | struct sock* other;
|
| 2427 |
|
| 2428 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 2429 | if(sock_soc_socket_is_valid_ipc(serversocket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 2430 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 2431 | return -1;
|
| 2432 | }
|
| 2433 | other = serversocket->sk;
|
| 2434 |
|
| 2435 | sk_soc_info("sock_soc_state_lock_proc serverfd=%d \n", psock_rpmsg->serverfd);
|
| 2436 | unix_state_lock(other);
|
| 2437 | return 0;
|
| 2438 | }
|
| 2439 |
|
| 2440 | void sock_soc_state_unlock(struct sock *other)
|
| 2441 | {
|
| 2442 | struct ipc_socket *psocket_ipc = NULL;
|
| 2443 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2444 | sock_rpmsg.msg_type = MSG_TYPE_STATE_UNLOCK;
|
| 2445 |
|
| 2446 | //²éÕÒ·þÎñÆ÷¶Ë´úÀísocketÏà¹ØÐÅÏ¢
|
| 2447 | psocket_ipc = sock_soc_get_ipcsocket_by_proxysock(other);
|
| 2448 | if(psocket_ipc == NULL){
|
| 2449 | sk_soc_info("sock_soc_state_unlock failed, other->fd=%d\n ", other->sk_fd);
|
| 2450 | return;
|
| 2451 | }
|
| 2452 | //·þÎñÆ÷¶Ësocket fd
|
| 2453 | sock_rpmsg.serverfd = psocket_ipc->remotefd;
|
| 2454 | sock_rpmsg.serversock = psocket_ipc->remotesocket;
|
| 2455 | sock_rpmsg.clientsock = psocket_ipc->localsocket;
|
| 2456 | sk_soc_info("sock_soc_state_unlock serverfd=%d \n", sock_rpmsg.serverfd);
|
| 2457 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2458 | }
|
| 2459 |
|
| 2460 | int sock_soc_state_unlock_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2461 | {
|
| 2462 | struct socket* serversocket;
|
| 2463 | struct sock* other;
|
| 2464 |
|
| 2465 | serversocket = (struct socket*)psock_rpmsg->serversock;
|
| 2466 | if(sock_soc_socket_is_valid_ipc(serversocket, psock_rpmsg->clientsock) == -1){ //serversockÒѹرÕ
|
| 2467 | sk_soc_info("sock_soc_socket_is_valid is false \n");
|
| 2468 | return -1;
|
| 2469 | }
|
| 2470 | other = serversocket->sk;
|
| 2471 |
|
| 2472 | sk_soc_info("sock_soc_state_unlock_proc serverfd=%d \n", psock_rpmsg->serverfd);
|
| 2473 | unix_state_lock(other);
|
| 2474 | return 0;
|
| 2475 | }
|
| 2476 |
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2477 | void sock_soc_unix_bind(struct sockaddr_un *sunaddr)
|
| 2478 | {
|
| 2479 | struct ipc_socket *psocket_ipc = NULL;
|
| 2480 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2481 | sock_rpmsg.msg_type = MSG_TYPE_UNIX_BIND;
|
| 2482 |
|
| 2483 | memcpy(&sock_rpmsg.sockaddr, sunaddr, sizeof(struct sockaddr_un));
|
| 2484 | sk_soc_info("sock_soc_unix_bind sunaddr=%s\n", sunaddr->sun_path);
|
| 2485 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2486 | }
|
| 2487 |
|
| 2488 | int sock_soc_unix_bind_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2489 | {
|
| 2490 | struct sockaddr_un sunaddr = {0};
|
| 2491 | memcpy(&sunaddr, &psock_rpmsg->sockaddr, sizeof(struct sockaddr_un));
|
| 2492 | sk_soc_info("sock_soc_unix_bind_proc sunaddr=%s\n", sunaddr.sun_path);
|
| 2493 | sock_soc_insert_ipc_sunaddr(&sunaddr);
|
| 2494 | return 0;
|
| 2495 | }
|
| 2496 |
|
| 2497 | void sock_soc_unix_unbind(struct sockaddr_un *sunaddr)
|
| 2498 | {
|
| 2499 | struct ipc_socket *psocket_ipc = NULL;
|
| 2500 | struct sock_rpmsg sock_rpmsg = {0};
|
| 2501 | sock_rpmsg.msg_type = MSG_TYPE_UNIX_UNBIND;
|
| 2502 |
|
| 2503 | memcpy(&sock_rpmsg.sockaddr, sunaddr, sizeof(struct sockaddr_un));
|
| 2504 | sk_soc_info("sock_soc_unix_unbind sunaddr=%s\n", sunaddr->sun_path);
|
| 2505 | sock_send_ipc_msg(&sock_rpmsg);
|
| 2506 | }
|
| 2507 |
|
| 2508 | int sock_soc_unix_unbind_proc(struct sock_rpmsg* psock_rpmsg)
|
| 2509 | {
|
| 2510 | struct sockaddr_un sunaddr = {0};
|
| 2511 | memcpy(&sunaddr, &psock_rpmsg->sockaddr, sizeof(struct sockaddr_un));
|
| 2512 | sk_soc_info("sock_soc_unix_unbind_proc sunaddr=%s\n", sunaddr.sun_path);
|
| 2513 | sock_soc_del_ipc_sunaddr(&sunaddr);
|
| 2514 | return 0;
|
| 2515 | }
|
| 2516 |
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2517 | static int sock_create_icp_channel(T_ZDrvRpMsg_ActorID core_id, T_ZDrvRpMsg_ChID channel_id, unsigned int channel_size)
|
| 2518 | {
|
| 2519 | int retval;
|
| 2520 |
|
| 2521 | retval = sockSocCreateChannel (core_id, channel_id, channel_size);
|
| 2522 | if(retval != RPMSG_SUCCESS && retval != RPMSG_CHANNEL_ALREADY_EXIST)
|
| 2523 | goto out;
|
| 2524 |
|
| 2525 | sk_soc_info("sock_create_icp_channel success");
|
| 2526 | return retval;
|
| 2527 |
|
| 2528 | out:
|
| 2529 | sk_soc_err("could not create channel.");
|
| 2530 | return retval;
|
| 2531 | }
|
| 2532 |
|
| 2533 | static void sock_dld_handle(struct sock_rpmsg* sock_rpmsg)
|
| 2534 | {
|
| 2535 | int len;
|
| 2536 | len = sock_channel_write(&g_sock_chn_info, sock_rpmsg, sock_rpmsg->data_len + sizeof(struct sock_rpmsg));
|
| 2537 | sk_soc_info("sock_dld_handle len=%d, index=%d", len, sock_rpmsg->index);
|
| 2538 | return;
|
| 2539 | }
|
| 2540 | static void sock_uld_handle(struct sock_rpmsg* sock_rpmsg)
|
| 2541 | {
|
| 2542 | if(NULL == sock_rpmsg){
|
| 2543 | return;
|
| 2544 | }
|
| 2545 |
|
| 2546 | switch(sock_rpmsg->msg_type) {
|
| 2547 | case MSG_TYPE_FIND:
|
| 2548 | sock_soc_find_other_proc(sock_rpmsg);
|
| 2549 | break;
|
| 2550 | case MSG_TYPE_FIND_RESULT:
|
| 2551 | sock_soc_find_other_result_proc(sock_rpmsg);
|
| 2552 | break;
|
| 2553 | case MSG_TYPE_ADD_WAIT_QUEUE:
|
| 2554 | sock_soc_add_wait_queue_proc(sock_rpmsg);
|
| 2555 | break;
|
| 2556 | case MSG_TYPE_REMOVE_WAIT_QUEUE:
|
| 2557 | sock_soc_remove_wait_queue_proc(sock_rpmsg);
|
| 2558 | break;
|
| 2559 | case MSG_TYPE_SYNC_IPC_SOCKET:
|
| 2560 | sock_sync_ipc_socket_proc(sock_rpmsg);
|
| 2561 | break;
|
| 2562 | case MSG_TYPE_WAIT_FOR_PEER:
|
| 2563 | sock_wait_for_peer_proc(sock_rpmsg);
|
| 2564 | break;
|
| 2565 | case MSG_TYPE_DATA_READY:
|
| 2566 | sock_soc_sk_data_ready_proc(sock_rpmsg);
|
| 2567 | break;
|
| 2568 | case MSG_TYPE_SEND_MSG:
|
| 2569 | sock_soc_msg_send_proc(sock_rpmsg);
|
| 2570 | break;
|
| 2571 | case MSG_TYPE_ADD_SKB_QUEUE_TAIL:
|
| 2572 | sock_soc_add_skb_queue_tail_proc(sock_rpmsg);
|
| 2573 | break;
|
| 2574 | case MSG_TYPE_SET_PEER:
|
| 2575 | sock_soc_set_peer_proc(sock_rpmsg);
|
| 2576 | break;
|
| 2577 | case MSG_TYPE_RECVQ_FULL:
|
| 2578 | sock_soc_recvq_full_proc(sock_rpmsg);
|
| 2579 | break;
|
| 2580 | case MSG_TYPE_RECVQ_FULL_RESULT:
|
| 2581 | sock_soc_recvq_full_result_proc(sock_rpmsg);
|
| 2582 | break;
|
| 2583 | case MSG_TYPE_PEER_CLEAR:
|
| 2584 | sock_soc_unix_peer_clear_proc(sock_rpmsg);
|
| 2585 | break;
|
| 2586 | case MSG_TYPE_WAKE_UP_INTERRUPTIBLE_POLL:
|
| 2587 | sock_soc_wake_up_interruptible_poll_proc(sock_rpmsg);
|
| 2588 | break;
|
| 2589 | case MSG_TYPE_RECVQ_FULL_LOCKLESS_AND_DEAD:
|
| 2590 | sock_soc_recvq_full_lockless_and_dead_proc(sock_rpmsg);
|
| 2591 | break;
|
| 2592 | case MSG_TYPE_RECVQ_FULL_LOCKLESS_AND_DEAD_RESULT:
|
| 2593 | sock_soc_recvq_full_lockless_and_dead_result_proc(sock_rpmsg);
|
| 2594 | break;
|
| 2595 | case MSG_TYPE_TEST_FLAG:
|
| 2596 | sock_soc_test_flags_proc(sock_rpmsg);
|
| 2597 | break;
|
| 2598 | case MSG_TYPE_TEST_FLAG_RESULT:
|
| 2599 | sock_soc_test_flags_result_proc(sock_rpmsg);
|
| 2600 | break;
|
| 2601 | case MSG_TYPE_SOCK_PUT:
|
| 2602 | sock_soc_sock_put_proc(sock_rpmsg);
|
| 2603 | break;
|
| 2604 | case MSG_TYPE_GET_SOCKET_STATES:
|
| 2605 | sock_soc_get_state_proc(sock_rpmsg);
|
| 2606 | break;
|
| 2607 | case MSG_TYPE_GET_SOCKET_STATES_RESULT:
|
| 2608 | sock_soc_get_state_result_proc(sock_rpmsg);
|
| 2609 | break;
|
| 2610 | case MSG_TYPE_STREAM_CONNECT:
|
| 2611 | sock_soc_stream_connect_proc(sock_rpmsg);
|
| 2612 | break;
|
| 2613 | case MSG_TYPE_UPDATE_PEER:
|
| 2614 | sock_soc_update_peer_proc(sock_rpmsg);
|
| 2615 | break;
|
| 2616 | case MSG_TYPE_DGRAM_DISCONNECTED:
|
| 2617 | sock_soc_dgram_disconnected_proc(sock_rpmsg);
|
| 2618 | break;
|
| 2619 | case MSG_TYPE_STATE_LOCK:
|
| 2620 | sock_soc_state_lock_proc(sock_rpmsg);
|
| 2621 | break;
|
| 2622 | case MSG_TYPE_STATE_UNLOCK:
|
| 2623 | sock_soc_state_unlock_proc(sock_rpmsg);
|
| 2624 | break;
|
| 2625 | case MSG_TYPE_SOCK_HOLD:
|
| 2626 | sock_soc_sock_hold_proc(sock_rpmsg);
|
| 2627 | break;
|
| 2628 | case MSG_TYPE_RELEASE_PEER:
|
| 2629 | sock_soc_release_peer_proc(sock_rpmsg);
|
| 2630 | break;
|
| 2631 | case MSG_TYPE_NOTIFY_PROXY_CHANGE:
|
| 2632 | sock_soc_notify_proxy_change_to_server_proc(sock_rpmsg);
|
| 2633 | break;
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2634 | case MSG_TYPE_UNIX_BIND:
|
| 2635 | sock_soc_unix_bind_proc(sock_rpmsg);
|
| 2636 | break;
|
| 2637 | case MSG_TYPE_UNIX_UNBIND:
|
| 2638 | sock_soc_unix_unbind_proc(sock_rpmsg);
|
| 2639 | break;
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2640 | default:
|
| 2641 | break;
|
| 2642 | }
|
| 2643 | }
|
| 2644 |
|
| 2645 | static int sock_receive_thread(void *argv)
|
| 2646 | {
|
| 2647 | int index,ret_len,i,num;
|
| 2648 | unsigned long flags;
|
| 2649 | //static struct sock_rpmsg sock_rpmsg = {0};
|
| 2650 | static char recvbuf[SOCK_DATA_MAX_LEN] = {0};
|
| 2651 | sk_soc_info("sock_receive_thread process");
|
| 2652 | while(1){
|
| 2653 | if(0 < sock_channel_read(&g_sock_chn_info, recvbuf, sizeof(recvbuf))) {
|
| 2654 | //sk_soc_info("sock_receive_thread sock_rpmsg.msg_type=%d,index=%d", sock_rpmsg.msg_type, sock_rpmsg.index);
|
| 2655 | #if 1
|
| 2656 | sock_recv_ipc_msg((struct sock_rpmsg*)recvbuf);
|
| 2657 | #else
|
| 2658 | switch(sock_rpmsg.msg_type) {
|
| 2659 | case MSG_TYPE_FIND:
|
| 2660 | sock_soc_find_other_proc(&sock_rpmsg);
|
| 2661 | break;
|
| 2662 | case MSG_TYPE_FIND_RESULT:
|
| 2663 | sock_soc_find_other_result_proc(&sock_rpmsg);
|
| 2664 | break;
|
| 2665 | case MSG_TYPE_ADD_WAIT_QUEUE:
|
| 2666 | sock_soc_add_wait_queue_proc(&sock_rpmsg);
|
| 2667 | break;
|
| 2668 | case MSG_TYPE_REMOVE_WAIT_QUEUE:
|
| 2669 | sock_soc_remove_wait_queue_proc(&sock_rpmsg);
|
| 2670 | break;
|
| 2671 | case MSG_TYPE_SYNC_IPC_SOCKET:
|
| 2672 | sock_sync_ipc_socket_proc(&sock_rpmsg);
|
| 2673 | break;
|
| 2674 | case MSG_TYPE_WAIT_FOR_PEER:
|
| 2675 | sock_wait_for_peer_proc(&sock_rpmsg);
|
| 2676 | break;
|
| 2677 | case MSG_TYPE_DATA_READY:
|
| 2678 | sock_soc_sk_data_ready_proc(&sock_rpmsg);
|
| 2679 | break;
|
| 2680 | case MSG_TYPE_SEND_MSG:
|
| 2681 | sock_soc_msg_send_proc(&sock_rpmsg);
|
| 2682 | break;
|
| 2683 | case MSG_TYPE_ADD_SKB_QUEUE_TAIL:
|
| 2684 | sock_soc_add_skb_queue_tail_proc(&sock_rpmsg);
|
| 2685 | break;
|
| 2686 | case MSG_TYPE_SET_PEER:
|
| 2687 | sock_soc_set_peer_proc(&sock_rpmsg);
|
| 2688 | break;
|
| 2689 | case MSG_TYPE_RECVQ_FULL:
|
| 2690 | sock_soc_recvq_full_proc(&sock_rpmsg);
|
| 2691 | break;
|
| 2692 | case MSG_TYPE_RECVQ_FULL_RESULT:
|
| 2693 | sock_soc_recvq_full_result_proc(&sock_rpmsg);
|
| 2694 | break;
|
| 2695 | case MSG_TYPE_PEER_CLEAR:
|
| 2696 | sock_soc_unix_peer_clear_proc(&sock_rpmsg);
|
| 2697 | break;
|
| 2698 | case MSG_TYPE_WAKE_UP_INTERRUPTIBLE_POLL:
|
| 2699 | sock_soc_wake_up_interruptible_poll_proc(&sock_rpmsg);
|
| 2700 | break;
|
| 2701 | case MSG_TYPE_RECVQ_FULL_LOCKLESS_AND_DEAD:
|
| 2702 | sock_soc_recvq_full_lockless_and_dead_proc(&sock_rpmsg);
|
| 2703 | break;
|
| 2704 | case MSG_TYPE_RECVQ_FULL_LOCKLESS_AND_DEAD_RESULT:
|
| 2705 | sock_soc_recvq_full_lockless_and_dead_result_proc(&sock_rpmsg);
|
| 2706 | break;
|
| 2707 | case MSG_TYPE_TEST_FLAG:
|
| 2708 | sock_soc_test_flags_proc(&sock_rpmsg);
|
| 2709 | break;
|
| 2710 | case MSG_TYPE_TEST_FLAG_RESULT:
|
| 2711 | sock_soc_test_flags_result_proc(&sock_rpmsg);
|
| 2712 | break;
|
| 2713 | case MSG_TYPE_SOCK_PUT:
|
| 2714 | sock_soc_sock_put_proc(&sock_rpmsg);
|
| 2715 | break;
|
| 2716 | case MSG_TYPE_GET_SOCKET_STATES:
|
| 2717 | sock_soc_get_state_proc(&sock_rpmsg);
|
| 2718 | break;
|
| 2719 | case MSG_TYPE_GET_SOCKET_STATES_RESULT:
|
| 2720 | sock_soc_get_state_result_proc(&sock_rpmsg);
|
| 2721 | break;
|
| 2722 | case MSG_TYPE_STREAM_CONNECT:
|
| 2723 | sock_soc_stream_connect_proc(&sock_rpmsg);
|
| 2724 | break;
|
| 2725 | case MSG_TYPE_UPDATE_PEER:
|
| 2726 | sock_soc_update_peer_proc(&sock_rpmsg);
|
| 2727 | break;
|
| 2728 | case MSG_TYPE_SOCKET_RELEASE:
|
| 2729 | sock_soc_release_sock_proc(&sock_rpmsg);
|
| 2730 | break;
|
| 2731 | case MSG_TYPE_DGRAM_DISCONNECTED:
|
| 2732 | sock_soc_dgram_disconnected_proc(&sock_rpmsg);
|
| 2733 | break;
|
| 2734 | case MSG_TYPE_STATE_LOCK:
|
| 2735 | sock_soc_state_lock_proc(&sock_rpmsg);
|
| 2736 | break;
|
| 2737 | case MSG_TYPE_STATE_UNLOCK:
|
| 2738 | sock_soc_state_unlock_proc(&sock_rpmsg);
|
| 2739 | break;
|
| 2740 | case MSG_TYPE_SOCK_HOLD:
|
| 2741 | sock_soc_sock_hold_proc(&sock_rpmsg);
|
| 2742 | break;
|
| 2743 | case MSG_TYPE_RELEASE_PEER:
|
| 2744 | sock_soc_release_peer_proc(&sock_rpmsg);
|
| 2745 | break;
|
| 2746 | case MSG_TYPE_NOTIFY_PROXY_CHANGE:
|
| 2747 | sock_soc_notify_proxy_change_to_server_proc(&sock_rpmsg);
|
| 2748 | break;
|
| 2749 | default:
|
| 2750 | break;
|
| 2751 | }
|
| 2752 | #endif
|
| 2753 | }
|
| 2754 | else {
|
| 2755 | sk_soc_err("sock_channel_read fail.");
|
| 2756 | msleep(1000);
|
| 2757 | continue;
|
| 2758 | }
|
| 2759 |
|
| 2760 | }
|
| 2761 |
|
| 2762 | sk_soc_err("The receive thread exit!");
|
| 2763 | return 0;
|
| 2764 | }
|
| 2765 |
|
| 2766 | static int sock_main_thread(void *argv)
|
| 2767 | {
|
| 2768 | struct list_head tmp_list;
|
| 2769 | struct sock_rpmsg *entry,*tmp_entry;
|
| 2770 | unsigned long flags;
|
| 2771 | struct sock_thread_info* p_main_thread_info;
|
| 2772 | p_main_thread_info = &g_sock_chn_info.main_thread_info;
|
| 2773 |
|
| 2774 | while(!p_main_thread_info->bstop) {
|
| 2775 | sock_get_sema(&p_main_thread_info->p_sock_sem);
|
| 2776 |
|
| 2777 | spin_lock_irqsave(&p_main_thread_info->p_sock_lock,flags);
|
| 2778 | if (list_empty(&p_main_thread_info->p_sock_list)) {
|
| 2779 | spin_unlock_irqrestore(&p_main_thread_info->p_sock_lock,flags);
|
| 2780 | continue;
|
| 2781 | }
|
| 2782 | list_replace_init(&p_main_thread_info->p_sock_list,&tmp_list);
|
| 2783 | list_del_init(&p_main_thread_info->p_sock_list);
|
| 2784 | spin_unlock_irqrestore(&p_main_thread_info->p_sock_lock,flags);
|
| 2785 |
|
| 2786 | list_for_each_entry_safe(entry,tmp_entry,&tmp_list,list) {
|
| 2787 | if(DIR_DOWNLINK == entry->dir) {
|
| 2788 | sock_dld_handle(entry);
|
| 2789 | }
|
| 2790 | else if(DIR_UPLINK == entry->dir) {
|
| 2791 | sock_uld_handle(entry);
|
| 2792 | }
|
| 2793 | else {
|
| 2794 | sk_soc_warn("sock data unknow dir(%d).",entry->dir);
|
| 2795 | }
|
| 2796 | list_del(&entry->list);
|
| 2797 | kfree(entry);
|
| 2798 | }
|
| 2799 | }
|
| 2800 |
|
| 2801 | sk_soc_err("the sock_main_thread stop!\n");
|
| 2802 | return 0;
|
| 2803 | }
|
| 2804 |
|
| 2805 | static int __init sock_soc_init(void)
|
| 2806 | {
|
| 2807 | struct task_struct *th = NULL;
|
| 2808 | int retval = 0;
|
| 2809 | struct sock_thread_info* p_main_thread_info;
|
| 2810 |
|
| 2811 | sema_init(&g_sock_sem, 0);
|
| 2812 | g_sock_chn_info.core_id = CAP_ID;
|
| 2813 | g_sock_chn_info.channel_id = ICP_CHN_SOCKET;
|
| 2814 | g_sock_chn_info.channel_size = ICP_CHANNEL_SIZE;
|
| 2815 |
|
| 2816 | sk_soc_info("sock_soc_init process");
|
| 2817 | INIT_HLIST_HEAD(&g_ipc_sockets);
|
| 2818 | INIT_HLIST_HEAD(&g_sock_rpmsg_info);
|
| 2819 | INIT_HLIST_HEAD(&g_sockets_info);
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2820 | INIT_HLIST_HEAD(&g_sunaddr_info);
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2821 | retval = sock_create_icp_channel(CAP_ID, ICP_CHN_SOCKET, ICP_CHANNEL_SIZE);
|
| 2822 | if(retval < 0) {
|
| 2823 | sk_soc_err("Create IcpChannel channel_32 fail.");
|
| 2824 | return retval;
|
| 2825 | }
|
| 2826 |
|
| 2827 | p_main_thread_info = &g_sock_chn_info.main_thread_info;
|
| 2828 |
|
| 2829 | INIT_LIST_HEAD(&p_main_thread_info->p_sock_list);
|
| 2830 | spin_lock_init(&p_main_thread_info->p_sock_lock);
|
| 2831 | sema_init(&p_main_thread_info->p_sock_sem, 0);
|
| 2832 |
|
| 2833 | th = kthread_run(sock_main_thread, 0, "sock-soc-main%d", ICP_CHN_SOCKET);
|
| 2834 | if (IS_ERR(th)) {
|
| 2835 | sk_soc_err("Unable to start receive thread.");
|
| 2836 | return PTR_ERR(th);
|
| 2837 | }
|
| 2838 | g_sock_chn_info.main_thread_info.p_thread = th;
|
| 2839 |
|
| 2840 | th = kthread_run(sock_receive_thread, 0, "sock-soc-recv%d", ICP_CHN_SOCKET);
|
| 2841 | if (IS_ERR(th)) {
|
| 2842 | sk_soc_err("Unable to start receive thread.");
|
| 2843 | return PTR_ERR(th);
|
| 2844 | }
|
| 2845 | g_sock_chn_info.recv_thread_info.p_thread = th;
|
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 2846 |
|
| 2847 | ipcsocket_debugfs_dir_entry_root = debugfs_create_dir("ipc_socket", NULL);
|
| 2848 | if (ipcsocket_debugfs_dir_entry_root)
|
| 2849 | ipcsocket_debugfs_dir_entry_proc = debugfs_create_dir("proc",
|
| 2850 | ipcsocket_debugfs_dir_entry_root);
|
| 2851 |
|
| 2852 | if (ipcsocket_debugfs_dir_entry_root) {
|
| 2853 | debugfs_create_file("ipc_socket_info",
|
| 2854 | 0444,
|
| 2855 | ipcsocket_debugfs_dir_entry_root,
|
| 2856 | NULL,
|
| 2857 | &ipc_socket_info_fops);
|
| 2858 | }
|
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 2859 | return 0;
|
| 2860 | }
|
| 2861 |
|
| 2862 | static void __exit sock_soc_exit(void)
|
| 2863 | {
|
| 2864 | memset(&g_sock_chn_info, 0, sizeof(struct sock_channel));
|
| 2865 | sk_soc_warn("success.\n");
|
| 2866 | }
|
| 2867 |
|
| 2868 | late_initcall(sock_soc_init);
|
| 2869 | module_exit(sock_soc_exit);
|
| 2870 |
|
| 2871 | MODULE_AUTHOR("ZXIC");
|
| 2872 | MODULE_DESCRIPTION("ZXIC CAP LAN NET DEVICE");
|
| 2873 | MODULE_LICENSE("GPL");
|
| 2874 |
|