Merge "[Feature][T8TSK-186][Sdk-ready]0.0.0.0->127.0.0.1" into MR3.0
diff --git a/meta/meta-mediatek-mt2735/recipes-lynq/lynq-at-test/lynq-at-test.bb b/meta/meta-mediatek-mt2735/recipes-lynq/lynq-at-test/lynq-at-test.bb
new file mode 100755
index 0000000..e660588
--- /dev/null
+++ b/meta/meta-mediatek-mt2735/recipes-lynq/lynq-at-test/lynq-at-test.bb
@@ -0,0 +1,27 @@
+DESCRIPTION = "at test"
+LICENSE = "CLOSED"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=e1696b147d49d491bcb4da1a57173fff"
+
+inherit workonsrc
+WORKONSRC = "${TOPDIR}/../src/lynq/packages/apps/lynq-at-test/src"
+DEPENDS += "platform-libs mipc "
+
+LDFLAGS_append = " -lmipc_msg"
+
+
+FILES_${PN} = "/data/ ${bindir} "
+TARGET_CC_ARCH += "${LDFLAGS}"
+
+
+do_compile () {
+	if test "${PACKAGE_ARCH}" = "cortexa7hf-vfp-vfpv4-neon" || test "${PACKAGE_ARCH}" = "cortexa7hf-neon-vfpv4"; then
+		oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST} -mhard-float"
+	else
+		oe_runmake all ROOT=${STAGING_DIR_HOST} OFLAGS="--sysroot=${STAGING_DIR_HOST}"
+	fi
+}
+
+do_install() {
+	install -d ${D}${bindir}/
+	install -m 0755 ${S}/lynq-at-test ${D}${bindir}/
+}
diff --git a/meta/meta-mediatek-mt2735/recipes-lynq/packagegroups/packagegroup-lync-mt2735.bb b/meta/meta-mediatek-mt2735/recipes-lynq/packagegroups/packagegroup-lync-mt2735.bb
index 2887cdd..0fcdeaa 100755
--- a/meta/meta-mediatek-mt2735/recipes-lynq/packagegroups/packagegroup-lync-mt2735.bb
+++ b/meta/meta-mediatek-mt2735/recipes-lynq/packagegroups/packagegroup-lync-mt2735.bb
@@ -33,6 +33,7 @@
     lynq-function-test \
     lynq-low-power \
     lynq-at-extension \
+    lynq-at-test \
     liblynq-logdata-handle \
     lynq-default \
     lynq-logrotate-service \
diff --git a/src/lynq/lib/liblynq-call/lynq_module_socket.cpp b/src/lynq/lib/liblynq-call/lynq_module_socket.cpp
index ff45c02..2d5b0e8 100755
--- a/src/lynq/lib/liblynq-call/lynq_module_socket.cpp
+++ b/src/lynq/lib/liblynq-call/lynq_module_socket.cpp
@@ -16,11 +16,12 @@
 #include "lynq_module_socket.h"

 #include "liblog/lynq_deflog.h"

 #include "lynq_shm.h"

+#include "lynq_urc_socket.h"

 

 #define LYNQ_SERVICE_PORT 8088

 #define LYNQ_ADDRESS "127.0.0.1"

-#define LYNQ_URC_SERVICE_PORT 8086

-#define LYNQ_URC_ADDRESS "0.0.0.0"

+//#define LYNQ_URC_SERVICE_PORT 8086

+//#define LYNQ_URC_ADDRESS "0.0.0.0"

 #define LYNQ_REQUEST_PARAM_BUF 8192

 #define LYNQ_REC_BUF 8192

 

@@ -50,11 +51,11 @@
 lynq_resp_t response;

 

 int module_len_rc_addr_serv;

-int module_len_urc_addr_serv;

+//int module_len_urc_addr_serv;

 struct sockaddr_in module_rc_addr_serv;

-struct sockaddr_in module_urc_addr_serv;

+//struct sockaddr_in module_urc_addr_serv;

 static int module_rc_sock_fd = -1;

-static int module_urc_sock_fd = -1;

+//static int module_urc_sock_fd = -1;

 int module_urc_status = 1;

 int module_rc_status = 1;

 pthread_t module_urc_tid = -1;

@@ -129,11 +130,11 @@
 *  other:failure

 */

 const int waitResponse(Parcel*& p, int token,int time_out)

-{
+{

     int waitToken = token;

     int wakeup_token=-1;

     int resp_type;

-    struct timeval now;
+    struct timeval now;

     struct timespec timeout;  

     int ret;

     std::list<Parcel*>::iterator iter;

@@ -141,8 +142,8 @@
     

     gettimeofday(&now,NULL);

     timeout.tv_sec = now.tv_sec+time_out; //timeout is 1min

-    timeout.tv_nsec = now.tv_usec*1000;
-
+    timeout.tv_nsec = now.tv_usec*1000;

+

     LYINFLOG("%s wait token is %d, wait time is %d",__func__,waitToken,time_out);

     

     BLOCK_RECV_MSG_LOCK();

@@ -326,7 +327,8 @@
     while(module_urc_status)

     {

         bzero(urc_data,LYNQ_REC_BUF);

-        res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);

+        //res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);

+        res = lynq_recv_urc_msg(urc_data,sizeof(urc_data));

         if(res<sizeof(int32_t)*2)

         {

             LYERRLOG("thread_urc_recv step2 fail: res is %d",res);

@@ -460,44 +462,46 @@
 

 int lynq_setup_urc_socket()

 {

-    int on = 1;

-    int ret = 0;

-    module_len_urc_addr_serv = sizeof(sockaddr_in);

-    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

-    if (module_urc_sock_fd <0){

-        LYERRLOG("urc socket error");

-        return RESULT_ERROR;  

-    }

-    module_urc_addr_serv.sin_family = AF_INET;

-    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);

-    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);

-    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/

-    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

-    if(ret <0)

-    {

-        LYERRLOG("urc socket set error");

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-        return RESULT_ERROR;  

-    }

-    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));

-    if(ret <0)

-    {

-        LYERRLOG("urc socket bind error");

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-        return RESULT_ERROR;  

-    }

-    return RESULT_OK;

+//    int on = 1;

+//    int ret = 0;

+//    module_len_urc_addr_serv = sizeof(sockaddr_in);

+//    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

+//    if (module_urc_sock_fd <0){

+//        LYERRLOG("urc socket error");

+//        return RESULT_ERROR;

+//    }

+//    module_urc_addr_serv.sin_family = AF_INET;

+//    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);

+//    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);

+//    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/

+//    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

+//    if(ret <0)

+//    {

+//        LYERRLOG("urc socket set error");

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//        return RESULT_ERROR;

+//    }

+//    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));

+//    if(ret <0)

+//    {

+//        LYERRLOG("urc socket bind error");

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//        return RESULT_ERROR;

+//    }

+

+//    return RESULT_OK;

+    return lynq_register_urc_socket() > 0 ? RESULT_OK : RESULT_ERROR;

 }

 

 void lynq_close_urc_socket()

 {

-    if (module_urc_sock_fd >= 0)

-    {

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-    }  

+//    if (module_urc_sock_fd >= 0)

+//    {

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//    }

 }

 

 int lynq_start_all_urc_socket_thread()

diff --git a/src/lynq/lib/liblynq-data/lynq_data_urc.cpp b/src/lynq/lib/liblynq-data/lynq_data_urc.cpp
index 9f211eb..d527ed2 100755
--- a/src/lynq/lib/liblynq-data/lynq_data_urc.cpp
+++ b/src/lynq/lib/liblynq-data/lynq_data_urc.cpp
@@ -13,6 +13,7 @@
 #include "lynq_data_urc.h"
 #include "liblog/lynq_deflog.h"
 #include "lynq_shm.h"
+#include "lynq_urc_socket.h"
 
 #define LYNQ_REC_BUF 8192
 
@@ -76,7 +77,8 @@
     while(data_urc_recive_status)
     {
         bzero(urc_data,LYNQ_REC_BUF);
-        res = recvfrom(lynq_urc_sockfd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&urc_local_addr,(socklen_t*)&lynq_len_urc_addr_serv);
+//        res = recvfrom(lynq_urc_sockfd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&urc_local_addr,(socklen_t*)&lynq_len_urc_addr_serv);
+        res = lynq_recv_urc_msg(urc_data,sizeof(urc_data));
         
         if(res<sizeof(int32_t)*2)
         {
@@ -165,37 +167,38 @@
 
 int lynq_socket_recv_start()
 {
-    int rt=0;
-    int on=1;
-    struct sockaddr_in urc_local_addr;
-    pthread_attr_t attr;
-    lynq_urc_sockfd = socket(AF_INET,SOCK_DGRAM,0);
-    if(lynq_urc_sockfd < 0)
-    {
-        LYERRLOG("create socket for udp fail");
-        return -1;
-    }
-    urc_local_addr.sin_family = AF_INET;
-    urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
-    urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
-    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
-    rt = setsockopt(lynq_urc_sockfd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
-    if(rt<0)
-    {
-        LYERRLOG("SO_REUSEADDR fail");
-        close(lynq_urc_sockfd);
-        lynq_urc_sockfd = -1;
-        return -1;
-    }
-    rt = bind(lynq_urc_sockfd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
-    if (rt == -1)
-    {
-        LYERRLOG("bind failed");
-        close(lynq_urc_sockfd);
-        lynq_urc_sockfd = -1;
-        return -1;
-    }
-    return 0;
+//    int rt=0;
+//    int on=1;
+//    struct sockaddr_in urc_local_addr;
+//    pthread_attr_t attr;
+//    lynq_urc_sockfd = socket(AF_INET,SOCK_DGRAM,0);
+//    if(lynq_urc_sockfd < 0)
+//    {
+//        LYERRLOG("create socket for udp fail");
+//        return -1;
+//    }
+//    urc_local_addr.sin_family = AF_INET;
+//    urc_local_addr.sin_port = htons(LYNQ_URC_SERVICE_PORT);
+//    urc_local_addr.sin_addr.s_addr = htons(INADDR_ANY);
+//    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/
+//    rt = setsockopt(lynq_urc_sockfd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);
+//    if(rt<0)
+//    {
+//        LYERRLOG("SO_REUSEADDR fail");
+//        close(lynq_urc_sockfd);
+//        lynq_urc_sockfd = -1;
+//        return -1;
+//    }
+//    rt = bind(lynq_urc_sockfd ,(struct sockaddr*)&urc_local_addr, sizeof(urc_local_addr));
+//    if (rt == -1)
+//    {
+//        LYERRLOG("bind failed");
+//        close(lynq_urc_sockfd);
+//        lynq_urc_sockfd = -1;
+//        return -1;
+//    }
+//    return 0;
+    return lynq_register_urc_socket() > 0 ? 0 : -1;
 }
 
 int lynq_socket_recv_stop()
diff --git a/src/lynq/lib/liblynq-data/lynq_data_urc.h b/src/lynq/lib/liblynq-data/lynq_data_urc.h
index 7ac4f75..80069e8 100755
--- a/src/lynq/lib/liblynq-data/lynq_data_urc.h
+++ b/src/lynq/lib/liblynq-data/lynq_data_urc.h
@@ -27,4 +27,4 @@
 bool is_support_urc(int urc_id);
 void urc_msg_process(Parcel *p);
 
-#endif
\ No newline at end of file
+#endif
diff --git a/src/lynq/lib/liblynq-network/lynq_module_socket.cpp b/src/lynq/lib/liblynq-network/lynq_module_socket.cpp
index c3f7334..48353dc 100755
--- a/src/lynq/lib/liblynq-network/lynq_module_socket.cpp
+++ b/src/lynq/lib/liblynq-network/lynq_module_socket.cpp
@@ -16,11 +16,12 @@
 #include "lynq_module_socket.h"

 #include "liblog/lynq_deflog.h"

 #include "lynq_shm.h"

+#include "lynq_urc_socket.h"

 

 #define LYNQ_SERVICE_PORT 8088

 #define LYNQ_ADDRESS "127.0.0.1"

-#define LYNQ_URC_SERVICE_PORT 8086

-#define LYNQ_URC_ADDRESS "0.0.0.0"

+//#define LYNQ_URC_SERVICE_PORT 8086

+//#define LYNQ_URC_ADDRESS "0.0.0.0"

 #define LYNQ_REQUEST_PARAM_BUF 8192

 #define LYNQ_REC_BUF 8192

 

@@ -50,11 +51,11 @@
 lynq_resp_t response;

 

 int module_len_rc_addr_serv;

-int module_len_urc_addr_serv;

+//int module_len_urc_addr_serv;

 struct sockaddr_in module_rc_addr_serv;

-struct sockaddr_in module_urc_addr_serv;

+//struct sockaddr_in module_urc_addr_serv;

 static int module_rc_sock_fd = -1;

-static int module_urc_sock_fd = -1;

+//static int module_urc_sock_fd = -1;

 int module_urc_status = 1;

 int module_rc_status = 1;

 pthread_t module_urc_tid = -1;

@@ -129,11 +130,11 @@
 *  other:failure

 */

 const int waitResponse(Parcel*& p, int token,int time_out)

-{
+{

     int waitToken = token;

     int wakeup_token=-1;

     int resp_type;

-    struct timeval now;
+    struct timeval now;

     struct timespec timeout;  

     int ret;

     std::list<Parcel*>::iterator iter;

@@ -141,8 +142,8 @@
     

     gettimeofday(&now,NULL);

     timeout.tv_sec = now.tv_sec+time_out; //timeout is 1min

-    timeout.tv_nsec = now.tv_usec*1000;
-
+    timeout.tv_nsec = now.tv_usec*1000;

+

     LYINFLOG("%s wait token is %d, wait time is %d",__func__,waitToken,time_out);

     

     BLOCK_RECV_MSG_LOCK();

@@ -326,7 +327,8 @@
     while(module_urc_status)

     {

         bzero(urc_data,LYNQ_REC_BUF);

-        res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);

+        //res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);

+        res = lynq_recv_urc_msg(urc_data,sizeof(urc_data));

         if(res<sizeof(int32_t)*2)

         {

             LYERRLOG("thread_urc_recv step2 fail: res is %d",res);

@@ -460,44 +462,45 @@
 

 int lynq_setup_urc_socket()

 {

-    int on = 1;

-    int ret = 0;

-    module_len_urc_addr_serv = sizeof(sockaddr_in);

-    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

-    if (module_urc_sock_fd <0){

-        LYERRLOG("urc socket error");

-        return RESULT_ERROR;  

-    }

-    module_urc_addr_serv.sin_family = AF_INET;

-    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);

-    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);

-    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/

-    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

-    if(ret <0)

-    {

-        LYERRLOG("urc socket set error");

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-        return RESULT_ERROR;  

-    }

-    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));

-    if(ret <0)

-    {

-        LYERRLOG("urc socket bind error");

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-        return RESULT_ERROR;  

-    }

-    return RESULT_OK;

+//    int on = 1;

+//    int ret = 0;

+//    module_len_urc_addr_serv = sizeof(sockaddr_in);

+//    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

+//    if (module_urc_sock_fd <0){

+//        LYERRLOG("urc socket error");

+//        return RESULT_ERROR;

+//    }

+//    module_urc_addr_serv.sin_family = AF_INET;

+//    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);

+//    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);

+//    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/

+//    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

+//    if(ret <0)

+//    {

+//        LYERRLOG("urc socket set error");

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//        return RESULT_ERROR;

+//    }

+//    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));

+//    if(ret <0)

+//    {

+//        LYERRLOG("urc socket bind error");

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//        return RESULT_ERROR;

+//    }

+//    return RESULT_OK;

+    return lynq_register_urc_socket() > 0 ? RESULT_OK : RESULT_ERROR;

 }

 

 void lynq_close_urc_socket()

 {

-    if (module_urc_sock_fd >= 0)

-    {

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-    }  

+//    if (module_urc_sock_fd >= 0)

+//    {

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//    }

 }

 

 int lynq_start_all_urc_socket_thread()

diff --git a/src/lynq/lib/liblynq-shm/include/lynq_urc_socket.h b/src/lynq/lib/liblynq-shm/include/lynq_urc_socket.h
new file mode 100755
index 0000000..866d5c2
--- /dev/null
+++ b/src/lynq/lib/liblynq-shm/include/lynq_urc_socket.h
@@ -0,0 +1,24 @@
+/**

+ * @file shm.h

+ * @author hq

+ * @brief 

+ * @version 1.0

+ * @date 2022-12-16

+ * 

+ * @copyright Copyright (c) 2022

+ * 

+ */

+#ifndef __LYNQ_URC_SOCKET__

+#define __LYNQ_URC_SOCKET__

+

+#ifdef __cplusplus

+extern "C" {

+#endif

+int lynq_open_broadcast_urc_socket();

+int lynq_broadcast_urc_msg(void * msg, int size);

+int lynq_register_urc_socket();

+int lynq_recv_urc_msg(void * buffer, int size);

+#ifdef __cplusplus

+}

+#endif 

+#endif //#ifndef __LYNQ_URC_SOCKET__

diff --git a/src/lynq/lib/liblynq-shm/lynq_urc_socket.cpp b/src/lynq/lib/liblynq-shm/lynq_urc_socket.cpp
new file mode 100755
index 0000000..2ebf85f
--- /dev/null
+++ b/src/lynq/lib/liblynq-shm/lynq_urc_socket.cpp
@@ -0,0 +1,278 @@
+#include <stdio.h>

+#include <stdlib.h>

+#include <string.h>

+//#include <binder/Parcel.h>

+#include <sys/socket.h>

+#include <netinet/in.h>

+#include <arpa/inet.h>

+#include <errno.h>

+#include <stdbool.h>

+#include <sys/types.h>

+#include <unistd.h>

+#include "lynq_urc_socket.h"

+#include "log/log.h"

+#include <list>

+

+static int lynq_urc_socket_fd = 0;

+static int registered_urc_socket_port = 0;

+static int registered_urc_socket_fd = 0;

+

+static pthread_mutex_t s_urc_broadcast_mtx = PTHREAD_MUTEX_INITIALIZER;

+static std::list<struct sockaddr*> s_urc_broadcast_clients;

+

+static pthread_mutex_t s_urc_register_mtx = PTHREAD_MUTEX_INITIALIZER;

+

+#define LYNQ_URC_SERVER_LISTEN_PORT 8086

+#define LYNQ_URC_SERVER_LISTEN_ADDRESS "127.0.0.1"

+

+#define LYNQ_URC_CLIENT_PORT_START 7050

+#define LYNQ_URC_CLIENT_PORT_END 7099

+#define LYNQ_URC_CLIENT_LISTEN_ADDRESS "127.0.0.1"

+

+static void * receive_client_heartbeat(void *parm);

+static void find_all_client_to_notify_online();

+int lynq_open_broadcast_urc_socket()

+{

+    int ret = 0;

+    int on = 1;

+    pthread_mutex_lock(&s_urc_broadcast_mtx);

+

+    struct sockaddr_in addr_serv;

+    //Creating a Socket object

+    lynq_urc_socket_fd=socket(AF_INET,SOCK_DGRAM,0);

+    memset(&addr_serv, 0, sizeof(addr_serv));

+    addr_serv.sin_family =AF_INET;

+    addr_serv.sin_port = htons(LYNQ_URC_SERVER_LISTEN_PORT);

+    addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_SERVER_LISTEN_ADDRESS);

+    ret = setsockopt(lynq_urc_socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

+    if (ret < 0){

+        goto open_socket_exit;

+    }

+    ret = bind(lynq_urc_socket_fd,(struct sockaddr*)&addr_serv,sizeof(addr_serv));

+    if (ret < 0){

+        goto open_socket_exit;

+    }

+    //receive registion and display on at port

+    pthread_t thid;

+    if(pthread_create(&thid, NULL, receive_client_heartbeat, NULL) != 0) {

+        RLOGE("thread creation failed\n");

+        ret = -1;

+        goto open_socket_exit;

+    }

+

+    find_all_client_to_notify_online();

+

+open_socket_exit:

+    pthread_mutex_unlock(&s_urc_broadcast_mtx);

+    return ret == 0 ? lynq_urc_socket_fd: -1;

+}

+

+int lynq_broadcast_urc_msg(void * msg, int size)

+{

+    int all_ok = 1;

+    pthread_mutex_lock(&s_urc_broadcast_mtx);

+    for(auto it=s_urc_broadcast_clients.begin(); it != s_urc_broadcast_clients.end(); )

+    {

+        int len = sendto(lynq_urc_socket_fd, msg, size, 0, *it, sizeof(struct sockaddr_in));

+        if (len < 0)

+        {

+            struct sockaddr_in *addr_cli = (struct sockaddr_in *) *it;

+            printf("remove client %d now\n", ntohs(addr_cli->sin_port));

+            it = s_urc_broadcast_clients.erase(it);

+            free(addr_cli);

+            all_ok = 0;

+            continue;

+        }

+        it++;

+    }

+    pthread_mutex_unlock(&s_urc_broadcast_mtx);

+    return all_ok;

+}

+

+int lynq_register_urc_socket()

+{

+    int on = 0;

+    int ret = 0;

+    int len_s;

+    struct sockaddr_in addr_serv;

+    //Creating a Socket object

+    pthread_mutex_lock(&s_urc_register_mtx);

+    registered_urc_socket_fd=socket(AF_INET,SOCK_DGRAM,0);

+    memset(&addr_serv, 0, sizeof(addr_serv));

+    addr_serv.sin_family =AF_INET;

+    addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_CLIENT_LISTEN_ADDRESS);

+    if (registered_urc_socket_port > 0) {

+        on = 1;

+        ret = setsockopt(registered_urc_socket_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

+        addr_serv.sin_port = htons(registered_urc_socket_port);

+        ret = bind(registered_urc_socket_fd,(struct sockaddr*)&addr_serv,sizeof(addr_serv));

+        if (ret < 0){

+            goto register_socket_exit;

+        }

+    }

+    else

+    {

+        for(registered_urc_socket_port = LYNQ_URC_CLIENT_PORT_START; registered_urc_socket_port < LYNQ_URC_CLIENT_PORT_END; registered_urc_socket_port ++)

+        {

+            addr_serv.sin_port = htons(registered_urc_socket_port);

+            ret = bind(registered_urc_socket_fd,(struct sockaddr*)&addr_serv,sizeof(addr_serv));

+            if (ret < 0){

+                printf("bind socket %d fail\n", registered_urc_socket_port);

+                continue;

+            }

+            break;

+        }

+    }

+

+    addr_serv.sin_port = htons(LYNQ_URC_SERVER_LISTEN_PORT);

+    len_s = sendto(registered_urc_socket_fd, &registered_urc_socket_port, sizeof(registered_urc_socket_port), 0, (struct sockaddr *)&addr_serv,sizeof(addr_serv));

+    printf("send result %d %d\n", len_s, errno);

+register_socket_exit:

+    pthread_mutex_unlock(&s_urc_register_mtx);

+    printf("init result %d\n", ret);

+    return ret ==0 ? registered_urc_socket_fd : -1;

+}

+

+int lynq_recv_urc_msg(void * buffer, int size)

+{

+    int ret = 0;

+    struct sockaddr_in addr_serv;

+    socklen_t len_addr_serv = sizeof(addr_serv);

+    memset(&addr_serv, 0, sizeof(addr_serv));

+    printf("client %ul to recv now\n", pthread_self());

+    pthread_mutex_lock(&s_urc_register_mtx);

+    if (registered_urc_socket_fd <= 0) {

+        pthread_mutex_unlock(&s_urc_register_mtx);

+        return -1;

+    }

+    while(1)

+    {

+        memset(buffer, 0, 4);

+        ret = recvfrom(registered_urc_socket_fd, buffer, size,0,(struct sockaddr *)&addr_serv,(socklen_t*)&len_addr_serv);

+        if (ret > 0 && LYNQ_URC_SERVER_LISTEN_PORT == ntohs(addr_serv.sin_port))

+        {

+            if (ret == 4 && LYNQ_URC_SERVER_LISTEN_PORT == *((int*)buffer))

+            {

+                sendto(registered_urc_socket_fd, &registered_urc_socket_port, sizeof(registered_urc_socket_port), 0, (struct sockaddr *)&addr_serv,sizeof(addr_serv));

+                printf("to send ack of headbeat\n");

+                continue;

+            }

+        }

+        else

+        {

+            printf("not a server packet\n");

+            continue;

+        }

+        break;

+    }

+    pthread_mutex_unlock(&s_urc_register_mtx);

+    printf("client %ul recv %d\n", pthread_self(), ret);

+    return ret;

+}

+

+static void *receive_client_heartbeat(void *parm)

+{

+    RLOGE("receive_at thread start\n");

+    int recv = 0;

+    char buffer[1024] = {0};

+    while(1)

+    {

+        RLOGE("receive third at cmd\n");

+

+        socklen_t len = sizeof(struct sockaddr_in);

+        struct sockaddr* cli = (struct sockaddr*)malloc(len);

+        bzero(cli, len);

+        printf("to recv now\n");

+        recv = recvfrom(lynq_urc_socket_fd, buffer, 1024, 0, cli, &len);

+        if(recv < 0)

+        {

+            RLOGE("recv fail\n");

+            printf("recv fail\n");

+            free(cli);

+            continue;

+        }

+        printf("recv a packet %d \n", recv);

+        struct sockaddr_in * register_socket = (struct sockaddr_in*)cli;

+

+        int port = ntohs(register_socket->sin_port);

+        if (recv == 4 && port == *((int*)buffer))

+        {

+            printf("port is %d\n", port);

+            pthread_mutex_lock(&s_urc_broadcast_mtx);

+            s_urc_broadcast_clients.push_back(cli);

+            pthread_mutex_unlock(&s_urc_broadcast_mtx);

+            RLOGE("recvfrom from client\n");

+        }

+    }

+    return NULL;

+}

+static int exec_cmd(const char *str_cmd, char * str_cmd_ret, size_t max_len)

+{

+    FILE *fp;

+    //printf("to exec cmd:%s\n", str_cmd);

+    if((fp=popen(str_cmd,"r"))==NULL)

+    {

+        perror("popen error!");

+        return -1;

+    }

+    if((fread(str_cmd_ret,max_len,1,fp))<0)

+    {

+        perror("fread fail!");

+        fclose(fp);

+        return -1;

+    }

+    fclose(fp);

+    return 0;

+}

+

+static int lynq_split(char * str, int len, char delimiter, char * results[]) {

+    int ret = 0;

+    char * end = str + len - 1;

+    results[ret++] = str;

+    while(str < end) {

+        if (*str == delimiter) {

+            *str++ = '\0';

+            results[ret++] = str;

+            continue;

+        }

+        str++;

+    }

+    if (*str == delimiter) {

+        *str = '\0';

+    }

+

+    return ret;

+}

+

+static void find_all_client_to_notify_online()

+{

+    char buffer[1024] = {0};

+    char * split_lines[128]= {0};

+    int count = 0;

+    int port, len;

+    int local_port = LYNQ_URC_SERVER_LISTEN_PORT;

+    printf("find_all_client_to_notify_online\n");

+    if (exec_cmd("netstat -an | grep -e \"127\\.0\\.0\\.1:70[5-9][0-9]\" | awk '{print $4}' | awk -F \":\" '{print $2}'", buffer, 1024) == 0)

+    {

+         count = lynq_split(buffer, 1024, '\n', split_lines);

+         for(int i=0; i < count;i++)

+         {

+             port = atoi(split_lines[i]);

+             printf("got %s port:%d\n", split_lines[i], port);

+             if (port < LYNQ_URC_CLIENT_PORT_START || port > LYNQ_URC_CLIENT_PORT_END)

+                 continue;

+

+             struct sockaddr_in addr_serv;

+             memset(&addr_serv, 0, sizeof(addr_serv));

+             addr_serv.sin_family =AF_INET;

+             addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_CLIENT_LISTEN_ADDRESS);

+             addr_serv.sin_port = htons(port);

+             len = sendto(lynq_urc_socket_fd, &local_port, sizeof(local_port), 0, (struct sockaddr *)&addr_serv,sizeof(addr_serv));

+             printf("send result %d %d\n", len, errno);

+         }

+    }

+    else

+    {

+        printf("net stat fail\n");

+    }

+}

diff --git a/src/lynq/lib/liblynq-shm/makefile b/src/lynq/lib/liblynq-shm/makefile
index 806cc77..d49d358 100755
--- a/src/lynq/lib/liblynq-shm/makefile
+++ b/src/lynq/lib/liblynq-shm/makefile
@@ -20,8 +20,9 @@
     -L. \
     -ldl \
     -llog \
-#   -lbinder \
     -lpthread \
+	
+#   -lbinder \
 #   -lutils \
 #   -lcutils \
 
diff --git a/src/lynq/lib/liblynq-sms/lynq_module_socket.cpp b/src/lynq/lib/liblynq-sms/lynq_module_socket.cpp
index 8d012da..ce07df1 100755
--- a/src/lynq/lib/liblynq-sms/lynq_module_socket.cpp
+++ b/src/lynq/lib/liblynq-sms/lynq_module_socket.cpp
@@ -16,11 +16,12 @@
 #include "lynq_module_socket.h"

 #include "liblog/lynq_deflog.h"

 #include "lynq_shm.h"

+#include "lynq_urc_socket.h"

 

 #define LYNQ_SERVICE_PORT 8088

 #define LYNQ_ADDRESS "127.0.0.1"

-#define LYNQ_URC_SERVICE_PORT 8086

-#define LYNQ_URC_ADDRESS "0.0.0.0"

+//#define LYNQ_URC_SERVICE_PORT 8086

+//#define LYNQ_URC_ADDRESS "0.0.0.0"

 #define LYNQ_REQUEST_PARAM_BUF 8192

 #define LYNQ_REC_BUF 8192

 

@@ -50,11 +51,11 @@
 lynq_resp_t response;

 

 int module_len_rc_addr_serv;

-int module_len_urc_addr_serv;

+//int module_len_urc_addr_serv;

 struct sockaddr_in module_rc_addr_serv;

-struct sockaddr_in module_urc_addr_serv;

+//struct sockaddr_in module_urc_addr_serv;

 static int module_rc_sock_fd = -1;

-static int module_urc_sock_fd = -1;

+//static int module_urc_sock_fd = -1;

 int module_urc_status = 1;

 int module_rc_status = 1;

 pthread_t module_urc_tid = -1;

@@ -324,7 +325,8 @@
     while(module_urc_status)

     {

         bzero(urc_data,LYNQ_REC_BUF);

-        res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);

+        //res = recvfrom(module_urc_sock_fd,urc_data,sizeof(urc_data),0,(struct sockaddr *)&module_urc_addr_serv,(socklen_t*)&module_len_urc_addr_serv);

+        res = lynq_recv_urc_msg(urc_data,sizeof(urc_data));

         if(res<sizeof(int32_t)*2)

         {

             LYERRLOG("thread_urc_recv step2 fail: res is %d",res);

@@ -465,44 +467,45 @@
 

 int lynq_setup_urc_socket()

 {

-    int on = 1;

-    int ret = 0;

-    module_len_urc_addr_serv = sizeof(sockaddr_in);

-    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

-    if (module_urc_sock_fd <0){

-        LYERRLOG("urc socket error");

-        return RESULT_ERROR;  

-    }

-    module_urc_addr_serv.sin_family = AF_INET;

-    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);

-    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);

-    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/

-    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

-    if(ret <0)

-    {

-        LYERRLOG("urc socket set error");

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-        return RESULT_ERROR;

-    }

-    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));

-    if(ret <0)

-    {

-        LYERRLOG("urc socket bind error");

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-        return RESULT_ERROR;  

-    }

-    return RESULT_OK;

+//    int on = 1;

+//    int ret = 0;

+//    module_len_urc_addr_serv = sizeof(sockaddr_in);

+//    module_urc_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

+//    if (module_urc_sock_fd <0){

+//        LYERRLOG("urc socket error");

+//        return RESULT_ERROR;

+//    }

+//    module_urc_addr_serv.sin_family = AF_INET;

+//    module_urc_addr_serv.sin_port = htons(LYNQ_URC_SERVICE_PORT);

+//    module_urc_addr_serv.sin_addr.s_addr = inet_addr(LYNQ_URC_ADDRESS);

+//    /* Set socket to allow reuse of address and port, SO_REUSEADDR value is 2*/

+//    ret = setsockopt(module_urc_sock_fd,SOL_SOCKET,SO_REUSEADDR,&on,sizeof on);

+//    if(ret <0)

+//    {

+//        LYERRLOG("urc socket set error");

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//        return RESULT_ERROR;

+//    }

+//    ret = bind(module_urc_sock_fd ,(struct sockaddr*)&module_urc_addr_serv, sizeof(module_urc_addr_serv));

+//    if(ret <0)

+//    {

+//        LYERRLOG("urc socket bind error");

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//        return RESULT_ERROR;

+//    }

+//    return RESULT_OK;

+    return lynq_register_urc_socket() > 0 ? RESULT_OK : RESULT_ERROR;

 }

 

 void lynq_close_urc_socket()

 {

-    if (module_urc_sock_fd >= 0)

-    {

-        close(module_urc_sock_fd);

-        module_urc_sock_fd =-1;

-    }  

+//    if (module_urc_sock_fd >= 0)

+//    {

+//        close(module_urc_sock_fd);

+//        module_urc_sock_fd =-1;

+//    }

 }

 

 int lynq_start_all_urc_socket_thread()

diff --git a/src/lynq/packages/apps/lynq-at-test/src/main.cpp b/src/lynq/packages/apps/lynq-at-test/src/main.cpp
new file mode 100755
index 0000000..367a6bb
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-at-test/src/main.cpp
@@ -0,0 +1,121 @@
+
+/*============================================================================= 
+#     FileName: lynq-at-test
+#     Desc: about SIMAPI
+#     Author: lei 
+#     Version: V1.0
+#     LastChange: 2023-03-09 
+#     History: 
+# 
+=============================================================================*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "mipc_msg.h"
+#include "mipc_msg_tlv_api.h"
+#include "mipc_msg_tlv_const.h"
+#include "mipc_msg_host.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char str[] = "AT;AT+CSQ;AT+ECSQ;AT+CREG;AT+CEREG;AT+C5GREG;AT+COPS;AT+CFUN;AT+ERAT";
+
+int check_buf(char *str,char *cmd)
+{
+    char *q = (char *)calloc(64,sizeof(char));
+    strcpy(q, str);
+    char *name;
+    char cmp[16] = {0};
+    while(q != NULL)
+    {
+        name = strsep(&q,";");
+        //printf("name %s\n", name);
+        strcpy(cmp, name);
+        //printf("cmp %s\n", cmp);
+        if(!strncmp(cmp, cmd, strlen(cmp)))
+        {
+            //printf("equal\n");
+            return 1;
+        }
+        // if(name != NULL)
+        // {
+        //     printf("%s\n", name);
+        //     if(!strncmp(name, cmd, strlen(name)))
+        //     {
+        //         return 1;
+        //     }
+        // }
+    }
+    free(q);
+    return 0;
+}
+
+void uper_char(char *cmd)
+{
+    char *p = cmd;
+    while (*p != '\0')
+    {
+        if((*p >= 'a') && (*p <= 'z'))
+        {
+            *p = *p-32;
+        }
+        *p++;
+    }
+}
+
+void sendcmd(char *cmd)
+{
+    mipc_msg_t *msg_req_ptr = mipc_msg_init(MIPC_SYS_AT_REQ, (mipc_msg_sim_ps_id_enum)MIPC_PS0);
+    mipc_msg_t *msg_cnf_ptr = NULL;
+    mipc_result_enum result;
+    char *atcmd_res_ptr = NULL;//, *atci_res = NULL;
+    uint16_t atcmd_res_len;
+    mipc_msg_add_tlv(msg_req_ptr, MIPC_SYS_AT_REQ_T_ATCMD, strlen(cmd), cmd);
+    msg_cnf_ptr = mipc_msg_sync_timeout(msg_req_ptr);
+    mipc_msg_deinit(msg_req_ptr);
+    result = mipc_get_result(msg_cnf_ptr);
+    if (result == MIPC_RESULT_SUCCESS) {
+        atcmd_res_ptr = (char *)mipc_msg_get_val_ptr(msg_cnf_ptr, MIPC_SYS_AT_CNF_T_ATCMD, &atcmd_res_len);
+        //int res_len = strlen(atcmd_res_ptr);
+        //printf( "res_len is:%d, atcmd_res_len is %d\n", res_len, atcmd_res_len);
+        //strncpy(response, atcmd_res_ptr, res_len);
+        //response[res_len] = '\0';
+        //atcmd_res_ptr[atcmd_res_len] = '\0';
+        printf( "%s\n", atcmd_res_ptr);
+    } else {
+        printf( "Failed to execute:%d\n", result);
+    }
+    mipc_msg_deinit(msg_cnf_ptr);
+}
+
+int main(void)
+{
+    SETCOM("/dev/ttyCMIPC2");
+    mipc_init("atci");
+    printf( "set mipc_inited true (UANT)\n");
+    char cmd[256] = {0};
+    while (1)
+    {
+        printf("please input at cmd:\n");
+        fgets(cmd, 256, stdin);
+        cmd[strlen(cmd)-1]='\0';
+        uper_char(cmd);
+        if(check_buf(str, cmd))
+        {
+            sendcmd(cmd);
+        }
+        else
+        {
+            printf("we just support AT+CSQ AT+ECSQ AT+CREG AT+CEREG AT+C5GREG AT+COPS AT+CFUN AT+ERAT\n");
+        }
+        
+    }
+}
+#ifdef __cplusplus
+}
+#endif 
diff --git a/src/lynq/packages/apps/lynq-at-test/src/makefile b/src/lynq/packages/apps/lynq-at-test/src/makefile
new file mode 100755
index 0000000..bf048d7
--- /dev/null
+++ b/src/lynq/packages/apps/lynq-at-test/src/makefile
@@ -0,0 +1,64 @@
+SHELL = /bin/sh
+RM = rm -f
+
+LOCAL_CFLAGS := -Wall \
+                -g -Os \
+                -flto \
+                -DRIL_SHLIB \
+                -D_LINUX \
+
+$(warning ################# TARGET_PLATFORM: $(TARGET_PLATFORM))
+ifeq ($(strip $(TARGET_PLATFORM)), mt2731)
+#$(warning #################add for debug $(ROOT), $(includedir))
+$(warning ################# TARGET_PLATFORM_MT2731)
+    LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2731 \
+                    -DMD_93_SUPPORT
+else ifeq ($(strip $(TARGET_PLATFORM)), mt2635)
+$(warning ################# TARGET_PLATFORM_MT2635)
+    LOCAL_CFLAGS += -DTARGET_PLATFORM_MT2635 \
+                    -DMD_90_SUPPORT
+endif
+
+
+LOCAL_PATH   = .
+
+$(warning ################# ZHOUQUNCHAO ROOT: $(ROOT),includedir:$(includedir),LOCAL_PATH:$(LOCAL_PATH))
+LOCAL_C_INCLUDES = \
+  -I. \
+  -I$(LOCAL_PATH) \
+  -I$(ROOT)$(includedir)/ \
+  -I$(ROOT)$(includedir)/mipc/api  \
+  -I$(ROOT)$(includedir)/mipc/common  \
+  -I$(ROOT)$(includedir)/mipc/msg  \
+  -I$(ROOT)$(includedir)/mipc/external  \
+  -DLIB_GNSS_HAL_DIR='"$(libdir)"'
+
+LOCAL_C_INCLUDES+=$(DNS_FLAGS)
+
+LOCAL_LIBS := \
+    -L. \
+    -ldl \
+    -lstdc++ \
+    -llog \
+    -pthread \
+    -lmipc_msg \
+
+LOCAL_SRC_FILES_CPP = $(wildcard *.cpp gpio/*.cpp ril/*.cpp)
+LOCAL_SRC_FILES_C = $(wildcard *.c gps/*.c)
+EXECUTABLE = lynq-at-test
+
+OBJECTS=$(LOCAL_SRC_FILES_CPP:.cpp=.o) $(LOCAL_SRC_FILES_C:.c=.o)
+all: $(EXECUTABLE)
+
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) $(OBJECTS) $(LOCAL_LIBS) $(LOCAL_CFLAGS) $(LOCAL_C_INCLUDES) -o $@
+
+%.o: %.c
+	$(warning ----->build $<)
+	$(CC) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+%.o : %.cpp
+	$(CXX) $(LOCAL_C_INCLUDES) $(LOCAL_CFLAGS) $(LOCAL_LIBS) -o $@ -c $<
+
+.PHONY: clean
+clean:
+	$(RM) $(OBJECTS) $(EXECUTABLE)