#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <linux/types.h>
#include <netinet/in.h>
#ifdef __KERNEL__
#include <linux/inet.h>
#endif
#include <fcntl.h>
#include <sys/stat.h>
#define IPC_DATA_MAX_SIZE 1024
#define DP_CR5_SAF 0
#define AUDIO_MONITOR_EPT 125
#if !defined(AF_RPMSG) && !defined(__KERNEL__)
#define AF_RPMSG 44
#define PF_RPMSG AF_RPMSG
struct sockaddr_rpmsg {
__kernel_sa_family_t family;
__u32 vproc_id;
__u32 addr;
};
#define RPMSG_LOCALHOST ((__u32)~0UL)
#endif
#include <android/log.h>
#define LOG_TAG "ipc_test"
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
int output = open("/data/test.txt", O_WRONLY|O_CREAT|O_APPEND, S_IWUSR|S_IRGRP|S_IROTH);
int main(int argc, const char * argv[]) {
#if 1
int32_t remote, ret;
struct timeval tv = { .tv_usec = 300 * 1000 };
uint32_t* data[1024], len;
struct sockaddr_rpmsg servaddr, dst_addr;
bzero(&servaddr, sizeof(servaddr));
servaddr.family = AF_RPMSG;
servaddr.vproc_id = DP_CR5_SAF;
servaddr.addr = AUDIO_MONITOR_EPT;
for (int s = socket(servaddr.family, SOCK_SEQPACKET, 0), _m = 1; _m; _m--, s > 0 && close(s)) {
if (setsockopt(remote, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0)
ALOGE("Set rcv timeo failed");
if (setsockopt(remote, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0)
ALOGE("Set snd timeo failed");
ret = connect(remote, (struct sockaddr *)&servaddr, sizeof(servaddr));
while (true) {
ret = write(remote, data, len);
ret = read(remote, &ret, sizeof(ret));
}
}
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/unistd.h>
#include <linux/string.h>
#if defined(__KERNEL__)
#include <linux/inet.h>
#include <uapi/linux/rpmsg_socket.h>
#endif
#define DP_CR5_SAF 0
#define AUDIO_MONITOR_EPT 125
#if 1
#ifndef AF_RPMSG
#define AF_RPMSG 44
#define PF_RPMSG AF_RPMSG
struct sockaddr_rpmsg {
__kernel_sa_family_t family;
__u32 vproc_id;
__u32 addr;
};
#define RPMSG_LOCALHOST ((__u32)~0UL)
#endif
#endif
#if defined(__KERNEL__)
static int __init hello_init(void)
{
struct sockaddr_rpmsg servaddr, cliaddr;
printk(KERN_ALERT"~~~~~~~~~~~~~~~~~~~~~~~~Hello world~~~~~~~~~~~~~~~~~~~~~~~~\n");
memset(&servaddr, 0, sizeof(struct sockaddr_rpmsg));
servaddr.family = AF_RPMSG;
servaddr.vproc_id = DP_CR5_SAF;
servaddr.addr = 132;
int32_t buf[128], ret;
struct socket *sock = NULL;
struct msghdr msg;
struct kvec iov;
memset(&msg, 0, sizeof(msg));
msg.msg_name = &servaddr;
msg.msg_namelen = sizeof(servaddr);
if ((ret = sock_create(servaddr.family, SOCK_SEQPACKET, 0, &sock)) >= 0) {
printk(KERN_ALERT"kernel_connect ret=%d\n", kernel_connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr), 0));
for (uint32_t i = 0; i < 10; i++) {
buf[1] = 23333;
buf[0] = i;
iov.iov_base = buf;
iov.iov_len = 8;
ret = kernel_sendmsg(sock, &msg, &iov, 1, iov.iov_len);
printk(KERN_ALERT "sendmsg ret=%d\n", ret);
ret = kernel_recvmsg(sock, &msg, &iov, 1, iov.iov_len, 0);
printk(KERN_ALERT "recvmsg ret=%d, buf=%d, %d\n", ret, buf[0], buf[1]);
}
}
}
static void __exit hello_exit(void)
{
printk("Exit Hello world\n");
}
subsys_initcall(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("Gateway");
MODULE_DESCRIPTION("hello world");
MODULE_LICENSE("GPL");
#endif