[Feature][ZXW-33]merge ZXW 0428 version
Change-Id: I11f167edfea428d9fab198ff00ff1364932d1b0b
diff --git a/ap/lib/libatreg/Makefile b/ap/lib/libatreg/Makefile
new file mode 100755
index 0000000..ffcee4a
--- /dev/null
+++ b/ap/lib/libatreg/Makefile
@@ -0,0 +1,37 @@
+#*******************************************************************************
+# include ZTE library makefile
+#*******************************************************************************
+include $(COMMON_MK)
+
+LIB_STATIC = libatreg.a
+LIB_SHARED = libatreg.so
+
+OBJS = $(patsubst %.c,%.o,$(wildcard *.c))
+
+CFLAGS += -I$(zte_app_path)/zte_comm/at_ctl/inc
+CFLAGS += -I$(zte_lib_path)/libatutils
+CFLAGS += -I$(LINUX_DIR)/include
+
+CFLAGS += -g -Werror=implicit-function-declaration
+CFLAGS += -I$(zte_app_path)/include
+CFLAGS += -fPIC
+
+LDFLAGS += -shared
+
+
+#*******************************************************************************
+# targets
+#*******************************************************************************
+all: $(LIB_STATIC) $(LIB_SHARED)
+
+$(LIB_STATIC) : $(OBJS)
+ $(AR) rcs $(LIB_STATIC) $(OBJS)
+
+$(LIB_SHARED): $(OBJS)
+ $(CC) $(LDFLAGS) -o $@ $^
+
+romfs:
+ $(ROMFSINST) $(LIB_SHARED) /lib/$(LIB_SHARED)
+
+clean:
+ -$(RM) *.a *.o *.so $(LIB_SHARED) $(LIB_STATIC) $(OBJS)
diff --git a/ap/lib/libatreg/atreg.c b/ap/lib/libatreg/atreg.c
new file mode 100755
index 0000000..c3f1a50
--- /dev/null
+++ b/ap/lib/libatreg/atreg.c
@@ -0,0 +1,550 @@
+/**
+ * @file regist.c
+ * @brief Implementation of regist.c.
+ *
+ * Copyright (C) 2022 Sanechips Technology Co., Ltd.
+ * @author
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
+ *
+ */
+
+
+/*******************************************************************************
+ * Include header files *
+ *******************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <assert.h>
+#include <sys/ipc.h>
+
+#include "atreg_common.h"
+#include "message.h"
+#include "softap_log.h"
+#include "atreg_msg.h"
+
+
+/*******************************************************************************
+ * Macro definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Type definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local variable definitions *
+ *******************************************************************************/
+/** ATÉÏÏÂÎijõʼ»¯±êÖ¾ */
+int atreg_ser_cxt_is_init = 0;
+int atreg_info_cxt_is_init = 0;
+
+/** loglevel³õʼ»¯±êÖ¾ */
+static int loglevel_is_init = 0;
+
+/** ¹«¹²²¿·Ö³õʼ»¯±êÖ¾ */
+static int common_is_init = 0;
+
+
+/*******************************************************************************
+ * Global variable definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local function declarations *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local function implementations *
+ *******************************************************************************/
+/**
+ * @brief ³õʼ»¯ser ATÉÏÏÂÎÄ: atreg_ser_ctx
+ * @param ÎÞ
+ * @return ÎÞ
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void atreg_ser_init_proc()
+{
+ if(0 == atreg_ser_cxt_is_init) {
+ memset(&atreg_ser_ctx, 0, sizeof(atreg_ser_ctx));
+ memset(atreg_ser_dynamic_idpool, 0, sizeof(atreg_ser_dynamic_idpool));
+
+ INIT_LIST_HEAD(&atreg_ser_ctx.at_ser_list);
+ INIT_LIST_HEAD(&atreg_ser_ctx.at_ser_list_tmp);
+
+ pthread_mutex_init(&atreg_ser_ctx.at_ser_lock, NULL);
+ pthread_mutex_init(&atreg_ser_ctx.at_ser_lock_tmp, NULL);
+ pthread_mutex_init(&atreg_ser_ctx.at_ser_idpool_lock, NULL);
+
+ atreg_ser_cxt_is_init++;
+ slog(ATREG_PRINT, SLOG_NORMAL, "atreg_ser_init_proc init SUCCESS\n");
+ }
+
+ return;
+}
+
+
+/**
+ * @brief ³õʼ»¯info ATÉÏÏÂÎÄ: atreg_info_ctx
+ * @param ÎÞ
+ * @return ÎÞ
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void atreg_info_init_proc()
+{
+ if(0 == atreg_info_cxt_is_init) {
+ memset(&atreg_info_ctx, 0, sizeof(atreg_info_ctx));
+ memset(atreg_info_dynamic_idpool, 0, sizeof(atreg_info_dynamic_idpool));
+
+ INIT_LIST_HEAD(&atreg_info_ctx.at_info_list);
+ INIT_LIST_HEAD(&atreg_info_ctx.at_info_list_tmp);
+
+ pthread_mutex_init(&atreg_info_ctx.at_info_lock, NULL);
+ pthread_mutex_init(&atreg_info_ctx.at_info_lock_tmp, NULL);
+ pthread_mutex_init(&atreg_info_ctx.at_info_idpool_lock, NULL);
+
+ atreg_info_cxt_is_init++;
+ slog(ATREG_PRINT, SLOG_NORMAL, "atreg_info_init_proc init SUCCESS\n");
+ }
+
+ return;
+}
+
+
+/**
+ * @brief ´´½¨ÏûÏ¢´¦Àí×ÓÏß³Ì
+ * @param (in) ATÉÏÏÂÎÄ - common
+ * @return 0 - ³É¹¦
+ * ÆäËû - ʧ°Ü
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static int atreg_create_msg_thread(struct atreg_common_context_t *patreg_common_ctx)
+{
+ return pthread_create(&(patreg_common_ctx->threadid), NULL, (void *)atreg_msg_thread_entry, (void *)patreg_common_ctx);
+}
+
+
+/**
+ * @brief ³õʼ»¯È«¾ÖATÉÏÏÂÎÄ: atreg_ser_ctx, atreg_info_ctx, atreg_common_ctx
+ * @param (in) atreg_type ×¢²áµÄATÀàÐÍ: 0-ser, 1-info
+ * @return 0 - ³É¹¦
+ * ÆäËû - ʧ°Ü
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static int atreg_context_init(int atreg_type)
+{
+ if (0 == loglevel_is_init) {
+ loglevel_init();
+ loglevel_is_init++;
+ }
+
+ switch (atreg_type) {
+ case AT_REG_SER:
+ atreg_ser_init_proc();
+ break;
+
+ case AT_REG_INFO:
+ atreg_info_init_proc();
+ break;
+
+ default:
+ break;
+ }
+
+ if (0 == common_is_init) {
+ sem_init(&atreg_common_ctx.sem_id, 0, 0);
+ memset(&atreg_common_ctx.ts, 0, sizeof(struct timespec));
+
+ /* ÄÚ²¿¶¯Ì¬»ñȡԴģ¿éID£¬³õʼֵΪMODULE_ID_ATDYNAMIC_BASE */
+ atreg_common_ctx.modid = MODULE_ID_ATDYNAMIC_BASE;
+
+ while ((msgget(atreg_common_ctx.modid, IPC_CREAT|IPC_EXCL|0600)) == -1) {
+ atreg_common_ctx.modid++;
+
+ if (atreg_common_ctx.modid > MODULE_ID_ATDYNAMIC_END)
+ /* µ±at_ctx.modid´óÓÚMODULE_ID_ATDYNAMIC_ENDֵʱ£¬Ö÷¶¯¶ÏÑÔ */
+ softap_assert("atreg dynamic msg pipi not free timely!!!!!!!!!!!");
+ }
+
+ slog(ATREG_PRINT, SLOG_NORMAL, "atreg_context_init modid 0x%x\n", atreg_common_ctx.modid);
+
+ /* ´´½¨ÏûÏ¢´¦Àí×ÓÏß³Ì */
+ if (0 != atreg_create_msg_thread(&atreg_common_ctx))
+ return -1;
+
+ common_is_init++;
+ }
+
+ return 0;
+}
+
+
+/**
+ * @brief Ϊÿ¸ö×¢²áµÄser AT¹¹½¨ÊµÀý
+ * @param (in) at_cmd_prefix ×¢²áµÄser ATǰ׺
+ * @param (in) cb ×¢²áµÄ»Øµ÷º¯Êý
+ * @return ser ATʵÀý
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void *atreg_ser_construct_proc(char *at_cmd_prefix, ser_cb_proc cb)
+{
+ struct atreg_ser_instance_t *patreg_ser_instance = NULL;
+
+ patreg_ser_instance = (struct atreg_ser_instance_t *)malloc(sizeof(struct atreg_ser_instance_t));
+ if(NULL == patreg_ser_instance) {
+ return NULL;
+ }
+ memset(patreg_ser_instance, 0, sizeof(struct atreg_ser_instance_t));
+
+ strncpy(patreg_ser_instance->at_cmd_prefix, at_cmd_prefix, AT_CMD_PREFIX-1);
+ patreg_ser_instance->req_msg_id = -1;
+ patreg_ser_instance->rsp_msg_id = -1;
+ patreg_ser_instance->cb = cb;
+
+ return (void *)patreg_ser_instance;
+}
+
+
+/**
+ * @brief Ϊÿ¸ö×¢²áµÄinfo AT¹¹½¨ÊµÀý
+ * @param (in) at_cmd_prefix ×¢²áµÄinfo ATǰ׺
+ * @param (in) cb ×¢²áµÄ»Øµ÷º¯Êý
+ * @return info ATʵÀý
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void *atreg_info_construct_proc(char *at_cmd_prefix, ser_cb_proc cb)
+{
+ struct atreg_info_instance_t *patreg_info_instance = NULL;
+
+ patreg_info_instance = (struct atreg_info_instance_t *)malloc(sizeof(struct atreg_info_instance_t));
+ if(NULL == patreg_info_instance) {
+ return NULL;
+ }
+ memset(patreg_info_instance, 0, sizeof(struct atreg_info_instance_t));
+
+ strncpy(patreg_info_instance->at_cmd_prefix, at_cmd_prefix, AT_CMD_PREFIX-1);
+ patreg_info_instance->req_msg_id = -1;
+ patreg_info_instance->cb = cb;
+
+ return (void *)patreg_info_instance;
+}
+
+
+/**
+ * @brief Ϊÿ¸ö×¢²áµÄAT¹¹½¨ÊµÀý
+ * @param (in) at_cmd_prefix ×¢²áµÄATǰ׺
+ * @param (in) cb ×¢²áµÄ»Øµ÷º¯Êý
+ * @param (in) atreg_type ×¢²áµÄATÀàÐÍ: 0-ser, 1-info
+ * @return ATʵÀý
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void *atreg_construct(char *at_cmd_prefix, ser_cb_proc cb, int atreg_type)
+{
+ void* patreg = NULL;
+
+ switch (atreg_type) {
+ case AT_REG_SER:
+ patreg = atreg_ser_construct_proc(at_cmd_prefix, cb);
+ break;
+
+ case AT_REG_INFO:
+ patreg = atreg_info_construct_proc(at_cmd_prefix, cb);
+ break;
+
+ default:
+ break;
+ }
+
+ return patreg;
+}
+
+
+/**
+ * @brief Ϊÿ¸ö×¢²áµÄser AT¶¯Ì¬·ÖÅäreq_msg_idÓërsp_msg_id
+ * @param (out) patreg_ser_instance ×¢²áµÄser ATʵÀý
+ * @return ÎÞ
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void atreg_ser_allocation_proc(void* patreg_ser_instance)
+{
+ int i,j;
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_idpool_lock);
+ for (i =0; i < ATREG_SER_ID_MAX; i++) {
+ for (j = 7; j >= 0; j--) {
+ if (0 == atreg_ser_dynamic_idpool[i] & (1 << j)) {
+ ((struct atreg_ser_instance_t *)patreg_ser_instance)->req_msg_id = 8 * (i + 1) - (j + 1);
+ ((struct atreg_ser_instance_t *)patreg_ser_instance)->rsp_msg_id = 8 * (i + 1) - (j + 1) + 1;
+ atreg_ser_dynamic_idpool[i] = atreg_ser_dynamic_idpool[i] | (1 << j);
+ atreg_ser_dynamic_idpool[i] = atreg_ser_dynamic_idpool[i] | (1 << (j - 1));
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_idpool_lock);
+
+ return;
+ }
+ }
+ }
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_idpool_lock);
+
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_ser_allocation_proc id pool is FULL\n");
+
+ return;
+}
+
+
+/**
+ * @brief Ϊÿ¸ö×¢²áµÄinfo AT¶¯Ì¬·ÖÅäreq_msg_id
+ * @param (out) patreg_info_instance ×¢²áµÄinfo ATʵÀý
+ * @return ÎÞ
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void atreg_info_allocation_proc(void* patreg_info_instance)
+{
+ int i,j;
+ pthread_mutex_lock(&atreg_info_ctx.at_info_idpool_lock);
+ for (i = 0; i < ATREG_INFO_ID_MAX; i++) {
+ for (j = 7; j >= 0; j--) {
+ if (0 == atreg_info_dynamic_idpool[i] & (1 << j)) {
+ ((struct atreg_info_instance_t *)patreg_info_instance)->req_msg_id = 8 * (i + 1) - (j + 1) + 512;
+ atreg_info_dynamic_idpool[i] = atreg_info_dynamic_idpool[i] | (1 << j);
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_idpool_lock);
+
+ return;
+ }
+ }
+ }
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_idpool_lock);
+
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_info_allocation_proc id pool is FULL\n");
+
+ return;
+}
+
+
+/**
+ * @brief Ϊÿ¸ö×¢²áµÄAT¶¯Ì¬·ÖÅäreq_msg_idÓërsp_msg_id
+ * @param (in) atreg_type ×¢²áµÄATÀàÐÍ: 0-ser, 1-info
+ * @param (out) patreg_instance ×¢²áµÄATʵÀý
+ * @return ÎÞ
+ * @note ÎÞ
+ * @warning ÎÞ
+ */
+static void atreg_dynamic_id_allocation(void* patreg_instance, int atreg_type)
+{
+ switch (atreg_type) {
+ case AT_REG_SER:
+ atreg_ser_allocation_proc(patreg_instance);
+ break;
+
+ case AT_REG_INFO:
+ atreg_info_allocation_proc(patreg_instance);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/*******************************************************************************
+ * Global function implementations *
+ *******************************************************************************/
+int reg_at_serv_func(char *at_cmd_prefix, ser_cb_proc cb)
+{
+ int send_ret = -1;
+ struct atreg_ser_instance_t *patreg_ser_instance = NULL;
+ struct atreg_msg_t *patreg_msgdata = NULL;
+
+ if (NULL == at_cmd_prefix || NULL == cb) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: register_serv_func para wrong, at_cmd_prefix or cb is NULL\n");
+ return -1;
+ }
+
+ /* at_context³õʼ»¯ */
+ if (-1 == atreg_context_init(AT_REG_SER))
+ return -1;
+
+ /* ¹¹½¨atʵÀý */
+ patreg_ser_instance = (struct atreg_ser_instance_t *)atreg_construct(at_cmd_prefix, cb, AT_REG_SER);
+ if (NULL == patreg_ser_instance) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_construct AT %s fail!\n", at_cmd_prefix);
+ return -1;
+ }
+
+ /* ¶¯Ì¬·ÖÅäreq_msg_idÓërsp_msg_id */
+ atreg_dynamic_id_allocation((void *)patreg_ser_instance, AT_REG_SER);
+
+ /* »º´æatʵÀý */
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock_tmp);
+ list_add_tail((struct list_head *)patreg_ser_instance, &atreg_ser_ctx.at_ser_list_tmp);
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock_tmp);
+
+ /* ×¢²áatÖÁat_ctl */
+ patreg_msgdata = (struct atreg_msg_t *)malloc(sizeof(struct atreg_msg_t));
+ memset(patreg_msgdata, 0, sizeof(struct atreg_msg_t));
+ strncpy(patreg_msgdata->at_cmd_prefix, patreg_ser_instance->at_cmd_prefix, AT_CMD_PREFIX-1);
+ patreg_msgdata->req_msg_id = patreg_ser_instance->req_msg_id;
+ patreg_msgdata->rsp_msg_id = patreg_ser_instance->rsp_msg_id;
+ patreg_msgdata->type = AT_REG_SER;
+ patreg_msgdata->res = -1;
+
+ send_ret = ipc_send_message2(atreg_common_ctx.modid, MODULE_ID_AT_CTL, MSG_CMD_AT_REG_REQ, sizeof(struct atreg_msg_t), (unsigned char *)patreg_msgdata, 0);
+ if (0 != send_ret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: register_serv_func ipc fail!\n");
+ return -1;
+ }
+
+ free(patreg_msgdata);
+
+ atreg_wait_rsp(MSG_CMD_AT_REG_REQ);
+
+ return 0;
+}
+
+
+int unreg_at_serv_func(char *at_cmd_prefix)
+{
+ int send_ret = -1;
+ struct atreg_ser_instance_t *patreg_ser_instance = NULL;
+ struct atreg_msg_t *patreg_msgdata = NULL;
+
+ if (NULL == at_cmd_prefix) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: unregister_serv_func para wrong, at_cmd_prefix=NULL!\n");
+ return -1;
+ }
+
+
+ patreg_ser_instance = (struct atreg_ser_instance_t *)atreg_search_instance_by_prefix(at_cmd_prefix, AT_REG_SER);
+ if (NULL == patreg_ser_instance) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: unreg_at_serv_func AT %s not regist yet\n", at_cmd_prefix);
+ return -1;
+ }
+
+ patreg_msgdata = (struct atreg_msg_t *)malloc(sizeof(struct atreg_msg_t));
+ memset(patreg_msgdata, 0, sizeof(struct atreg_msg_t));
+ strncpy(patreg_msgdata->at_cmd_prefix, patreg_ser_instance->at_cmd_prefix, AT_CMD_PREFIX-1);
+ patreg_msgdata->req_msg_id = patreg_ser_instance->req_msg_id;
+ patreg_msgdata->rsp_msg_id = patreg_ser_instance->rsp_msg_id;
+ patreg_msgdata->type = AT_REG_SER;
+ patreg_msgdata->res = -1;
+
+ send_ret = ipc_send_message2(atreg_common_ctx.modid, MODULE_ID_AT_CTL, MSG_CMD_AT_UNREG_REQ, sizeof(struct atreg_msg_t), (unsigned char *)patreg_msgdata, 0);
+ if (0 != send_ret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: unregister_serv_func ipc fail!\n");
+ return -1;
+ }
+
+ free(patreg_msgdata);
+
+ atreg_wait_rsp(MSG_CMD_AT_UNREG_REQ);
+
+ return 0;
+}
+
+
+int reg_at_info_func(char *at_cmd_prefix, info_cb_proc cb)
+{
+ int send_ret = -1;
+ struct atreg_info_instance_t *patreg_info_instance = NULL;
+ struct atreg_msg_t *patreg_msgdata = NULL;
+
+ if (NULL == at_cmd_prefix || NULL == cb) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: register_info_func para wrong, at_cmd_prefix or cb is NULL\n");
+ return -1;
+ }
+
+ /* at_context³õʼ»¯ */
+ if (-1 == atreg_context_init(AT_REG_INFO))
+ return -1;
+
+ /* ¹¹½¨atʵÀý */
+ patreg_info_instance = (struct atreg_info_instance_t *)atreg_construct(at_cmd_prefix, cb, AT_REG_INFO);
+ if (NULL == patreg_info_instance) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_construct AT %s fail!\n", at_cmd_prefix);
+ return -1;
+ }
+
+ /* ¶¯Ì¬·ÖÅäreq_msg_id */
+ atreg_dynamic_id_allocation((void *)patreg_info_instance, AT_REG_INFO);
+
+ /* »º´æatʵÀý */
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock_tmp);
+ list_add_tail((struct list_head *)patreg_info_instance, &atreg_info_ctx.at_info_list_tmp);
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock_tmp);
+
+ /* ×¢²áatÖÁat_ctl */
+ patreg_msgdata = (struct atreg_msg_t *)malloc(sizeof(struct atreg_msg_t));
+ memset(patreg_msgdata, 0, sizeof(struct atreg_msg_t));
+ strncpy(patreg_msgdata->at_cmd_prefix, patreg_info_instance->at_cmd_prefix, AT_CMD_PREFIX-1);
+ patreg_msgdata->req_msg_id = patreg_info_instance->req_msg_id;
+ patreg_msgdata->rsp_msg_id = -1;
+ patreg_msgdata->type = AT_REG_INFO;
+ patreg_msgdata->res = -1;
+
+ send_ret = ipc_send_message2(atreg_common_ctx.modid, MODULE_ID_AT_CTL, MSG_CMD_AT_REG_REQ, sizeof(struct atreg_msg_t), (unsigned char *)patreg_msgdata, 0);
+ if (0 != send_ret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: register_info_func ipc fail!\n");
+ return -1;
+ }
+
+ free(patreg_msgdata);
+
+ atreg_wait_rsp(MSG_CMD_AT_REG_REQ);
+
+ return 0;
+}
+
+
+int unreg_at_info_func(char *at_cmd_prefix)
+{
+ int send_ret = -1;
+ struct atreg_info_instance_t *patreg_info_instance = NULL;
+ struct atreg_msg_t *patreg_msgdata = NULL;
+
+ if (NULL == at_cmd_prefix) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: unregister_info_func para wrong, at_cmd_prefix=NULL!\n");
+ return -1;
+ }
+
+ patreg_info_instance = (struct atreg_info_instance_t *)atreg_search_instance_by_prefix(at_cmd_prefix, AT_REG_INFO);
+ if (NULL == patreg_info_instance) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: unreg_at_info_func AT %s not regist yet\n", at_cmd_prefix);
+ return -1;
+ }
+
+ patreg_msgdata = (struct atreg_msg_t *)malloc(sizeof(struct atreg_msg_t));
+ memset(patreg_msgdata, 0, sizeof(struct atreg_msg_t));
+ strncpy(patreg_msgdata->at_cmd_prefix, patreg_info_instance->at_cmd_prefix, AT_CMD_PREFIX-1);
+ patreg_msgdata->req_msg_id = patreg_info_instance->req_msg_id;
+ patreg_msgdata->rsp_msg_id = -1;
+ patreg_msgdata->type = AT_REG_INFO;
+ patreg_msgdata->res = -1;
+
+ send_ret = ipc_send_message2(atreg_common_ctx.modid, MODULE_ID_AT_CTL, MSG_CMD_AT_UNREG_REQ, sizeof(struct atreg_msg_t), (unsigned char *)patreg_msgdata, 0);
+ if (0 != send_ret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: unregister_info_func ipc fail!\n");
+ return -1;
+ }
+
+ free(patreg_msgdata);
+
+ atreg_wait_rsp(MSG_CMD_AT_UNREG_REQ);
+
+ return 0;
+}
+
diff --git a/ap/lib/libatreg/atreg.h b/ap/lib/libatreg/atreg.h
new file mode 100755
index 0000000..40f3eb0
--- /dev/null
+++ b/ap/lib/libatreg/atreg.h
@@ -0,0 +1,53 @@
+/**
+ * @file regist.h
+ * @brief Inter APIs of libatreg
+ *
+ * Copyright (C) 2022 Sanechips Technology Co., Ltd.
+ * @author
+ * @ingroup
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+
+#ifndef _ATREG_REGIST_H
+#define _ATREG_REGIST_H
+
+
+/*******************************************************************************
+ * Include header files *
+ *******************************************************************************/
+#include "atreg_common.h"
+
+
+/*******************************************************************************
+ * Macro definitions *
+ *******************************************************************************/
+
+
+
+/*******************************************************************************
+ * Type definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Global variable declarations *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Global function declarations *
+ *******************************************************************************/
+int reg_at_serv_func(char *at_cmd_prefix, ser_cb_proc cb);
+int unreg_at_serv_func(char *at_cmd_prefix);
+
+int reg_at_info_func(char *at_cmd_prefix, info_cb_proc cb);
+int unreg_at_info_func(char *at_cmd_prefix);
+
+
+#endif
+
diff --git a/ap/lib/libatreg/atreg_common.c b/ap/lib/libatreg/atreg_common.c
new file mode 100755
index 0000000..84f8667
--- /dev/null
+++ b/ap/lib/libatreg/atreg_common.c
@@ -0,0 +1,264 @@
+/**
+ * @file atreg_common.c
+ * @brief Implementation of the inter APIs of libatreg.
+ *
+ * Copyright (C) 2021 Sanechips Technology Co., Ltd.
+ * @author
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
+ *
+ */
+
+
+/*******************************************************************************
+ * Include header files *
+ *******************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "atreg_common.h"
+#include "at_utils.h"
+
+
+/*******************************************************************************
+ * Macro definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Type definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local variable definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Global variable definitions *
+ *******************************************************************************/
+
+struct atreg_ser_context_t atreg_ser_ctx;
+struct atreg_info_context_t atreg_info_ctx;
+struct atreg_common_context_t atreg_common_ctx;
+
+/** ser - ¶¯Ì¬id³Ø, ·¶Î§: 0~511 */
+unsigned char atreg_ser_dynamic_idpool[ATREG_SER_ID_MAX];
+/** info - ¶¯Ì¬id³Ø, ·¶Î§: 512~768 */
+unsigned char atreg_info_dynamic_idpool[ATREG_INFO_ID_MAX];
+
+extern int atreg_ser_cxt_is_init;
+extern int atreg_info_cxt_is_init;
+/*******************************************************************************
+ * Local function declarations *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local function implementations *
+ *******************************************************************************/
+static void *atreg_ser_search_instance_by_prefix_proc(char *at_cmd_prefix)
+{
+ struct atreg_ser_instance_t * entry = NULL;
+
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock);
+ list_for_each_entry(entry, &atreg_ser_ctx.at_ser_list, list) {
+ if(0 == at_strncmp(at_cmd_prefix, entry->at_cmd_prefix, AT_CMD_PREFIX)) {
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock);
+
+ return (void *)entry;
+ }
+ }
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock);
+
+ return NULL;
+}
+
+
+static void *atreg_info_search_instance_by_prefix_proc(char *at_cmd_prefix)
+{
+ struct atreg_info_instance_t * entry = NULL;
+
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock);
+ list_for_each_entry(entry, &atreg_info_ctx.at_info_list, list) {
+ if(0 == at_strncmp(at_cmd_prefix, entry->at_cmd_prefix, AT_CMD_PREFIX)) {
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock);
+
+ return (void *)entry;
+ }
+ }
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock);
+
+ return NULL;
+}
+
+
+static void *atreg_ser_search_instance_by_reqid_proc(int req_msg_id)
+{
+ struct atreg_ser_instance_t *entry = NULL;
+
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock);
+ list_for_each_entry(entry, &atreg_ser_ctx.at_ser_list, list) {
+ if(entry->req_msg_id == req_msg_id) {
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock);
+
+ return (void *)entry;
+ }
+ }
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock);
+
+ return NULL;
+}
+
+
+static void *atreg_info_search_instance_by_reqid_proc(int req_msg_id)
+{
+ struct atreg_info_instance_t *entry = NULL;
+
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock);
+ list_for_each_entry(entry, &atreg_info_ctx.at_info_list, list) {
+ if(entry->req_msg_id == req_msg_id) {
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock);
+
+ return (void *)entry;
+ }
+ }
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock);
+
+ return NULL;
+}
+
+
+static void *atreg_ser_search_instance_tmp_by_reqid_proc(int req_msg_id)
+{
+ struct atreg_ser_instance_t *entry = NULL;
+
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock_tmp);
+ list_for_each_entry(entry, &atreg_ser_ctx.at_ser_list_tmp, list) {
+ if(entry->req_msg_id == req_msg_id) {
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock_tmp);
+
+ return (void *)entry;
+ }
+ }
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock_tmp);
+
+ return NULL;
+}
+
+
+static void *atreg_info_search_instance_tmp_by_reqid_proc(int req_msg_id)
+{
+ struct atreg_info_instance_t *entry = NULL;
+
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock_tmp);
+ list_for_each_entry(entry, &atreg_info_ctx.at_info_list_tmp, list) {
+ if(entry->req_msg_id == req_msg_id) {
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock_tmp);
+
+ return (void *)entry;
+ }
+ }
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock_tmp);
+
+ return NULL;
+}
+
+
+/*******************************************************************************
+ * Global function implementations *
+ *******************************************************************************/
+void atreg_wait_rsp(int msg_cmd)
+{
+ int ret = -1;
+
+ if (clock_gettime(CLOCK_REALTIME, &atreg_common_ctx.ts) == -1) {
+ slog(ATREG_PRINT, SLOG_NORMAL, "atreg_wait_rsp clock_gettime fail.\n");
+ return;
+ }
+ atreg_common_ctx.ts.tv_sec += WAIT_RSP_TIMEOUT;
+
+ while ((ret = sem_timedwait(&atreg_common_ctx.sem_id, &atreg_common_ctx.ts)) == -1 && errno == EINTR)
+ continue;
+ if(-1 == ret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_wait_rsp wait msg(%x) timeout.\n", msg_cmd);
+ }
+ else {
+ slog(ATREG_PRINT, SLOG_NORMAL, "atreg_wait_rsp post msg(%x) response.\n", msg_cmd);
+ }
+
+ return;
+}
+
+
+void *atreg_search_instance_by_prefix(char *at_cmd_prefix, int atreg_type)
+{
+ void* patreg = NULL;
+
+ switch (atreg_type) {
+ case AT_REG_SER:
+ patreg = atreg_ser_search_instance_by_prefix_proc(at_cmd_prefix);
+ break;
+
+ case AT_REG_INFO:
+ patreg = atreg_info_search_instance_by_prefix_proc(at_cmd_prefix);
+ break;
+
+ default:
+ break;
+ }
+
+ return patreg;
+}
+
+
+void *atreg_search_instance_tmp_by_reqid(int req_msg_id, int atreg_type)
+{
+ void* patreg = NULL;
+
+ switch (atreg_type) {
+ case AT_REG_SER:
+ patreg = atreg_ser_search_instance_tmp_by_reqid_proc(req_msg_id);
+ break;
+
+ case AT_REG_INFO:
+ patreg = atreg_info_search_instance_tmp_by_reqid_proc(req_msg_id);
+ break;
+
+ default:
+ break;
+ }
+
+ return patreg;
+}
+
+
+struct atreg_instance_and_type_t atreg_search_instance_and_type_by_reqid(int req_msg_id)
+{
+ void* patreg = NULL;
+ struct atreg_instance_and_type_t atreg_instance_and_type = {0};
+
+ if(atreg_ser_cxt_is_init)
+ patreg = atreg_ser_search_instance_by_reqid_proc(req_msg_id);
+ if (NULL != patreg) {
+ atreg_instance_and_type.type = AT_REG_SER;
+ atreg_instance_and_type.instance = patreg;
+
+ return atreg_instance_and_type;
+ }
+ if(atreg_info_cxt_is_init)
+ patreg = atreg_info_search_instance_by_reqid_proc(req_msg_id);
+ if (NULL != patreg) {
+ atreg_instance_and_type.type = AT_REG_INFO;
+ atreg_instance_and_type.instance = patreg;
+
+ return atreg_instance_and_type;
+ }
+ atreg_instance_and_type.type = -1;
+ return atreg_instance_and_type;
+}
+
diff --git a/ap/lib/libatreg/atreg_common.h b/ap/lib/libatreg/atreg_common.h
new file mode 100755
index 0000000..3ea1dc3
--- /dev/null
+++ b/ap/lib/libatreg/atreg_common.h
Binary files differ
diff --git a/ap/lib/libatreg/atreg_thread.c b/ap/lib/libatreg/atreg_thread.c
new file mode 100755
index 0000000..714cd01
--- /dev/null
+++ b/ap/lib/libatreg/atreg_thread.c
@@ -0,0 +1,349 @@
+/**
+ * @file at_thread.c
+ * @brief Implementation of at_thread.c.
+ *
+ * Copyright (C) 2022 Sanechips Technology Co., Ltd.
+ * @author
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
+ *
+ */
+
+
+/*******************************************************************************
+ * Include header files *
+ *******************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/ipc.h>
+#include <errno.h>
+
+#include "atreg_common.h"
+#include "message.h"
+#include "softap_log.h"
+#include "atreg_msg.h"
+
+
+/*******************************************************************************
+ * Macro definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Type definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local variable definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Global variable definitions *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local function declarations *
+ *******************************************************************************/
+
+
+/*******************************************************************************
+ * Local function implementations *
+ *******************************************************************************/
+static void atreg_ser_regist_rsp_proc(struct atreg_msg_t *patreg_msgdata)
+{
+ struct atreg_ser_instance_t *patreg_ser_instance = NULL;
+
+ if (0 == patreg_msgdata->res) {
+ patreg_ser_instance = (struct atreg_ser_instance_t *)atreg_search_instance_tmp_by_reqid(patreg_msgdata->req_msg_id, AT_REG_SER);
+ if (NULL != patreg_ser_instance) {
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock_tmp);
+ list_del((struct list_head *)patreg_ser_instance);
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock_tmp);
+
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock);
+ list_add_tail((struct list_head *)patreg_ser_instance, &atreg_ser_ctx.at_ser_list);
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock);
+
+ slog(ATREG_PRINT, SLOG_NORMAL, "AT %s regist success!\n", patreg_msgdata->at_cmd_prefix);
+ }
+ } else {
+ patreg_ser_instance = (struct atreg_ser_instance_t *)atreg_search_instance_tmp_by_reqid(patreg_msgdata->req_msg_id, AT_REG_SER);
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock_tmp);
+ list_del((struct list_head *)patreg_ser_instance);
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock_tmp);
+
+ slog(ATREG_PRINT, SLOG_ERR, "AT %s regist fail!\n", patreg_msgdata->at_cmd_prefix);
+
+ free(patreg_ser_instance);
+ }
+
+ return;
+}
+
+
+static void atreg_info_regist_rsp_proc(struct atreg_msg_t *patreg_msgdata)
+{
+ struct atreg_info_instance_t *patreg_info_instance = NULL;
+
+ if (0 == patreg_msgdata->res) {
+ patreg_info_instance = (struct atreg_info_instance_t *)atreg_search_instance_tmp_by_reqid(patreg_msgdata->req_msg_id, AT_REG_INFO);
+ if (NULL != patreg_info_instance) {
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock_tmp);
+ list_del((struct list_head *)patreg_info_instance);
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock_tmp);
+
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock);
+ list_add_tail((struct list_head *)patreg_info_instance, &atreg_info_ctx.at_info_list);
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock);
+
+ slog(ATREG_PRINT, SLOG_NORMAL, "AT %s regist success!\n", patreg_msgdata->at_cmd_prefix);
+ }
+ } else {
+ patreg_info_instance = (struct atreg_info_instance_t *)atreg_search_instance_tmp_by_reqid(patreg_msgdata->req_msg_id, AT_REG_INFO);
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock_tmp);
+ list_del((struct list_head *)patreg_info_instance);
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock_tmp);
+
+ slog(ATREG_PRINT, SLOG_ERR, "AT %s regist fail!\n", patreg_msgdata->at_cmd_prefix);
+
+ free(patreg_info_instance);
+ }
+
+ return;
+}
+
+
+static void atreg_regist_rsp_proc(unsigned char *aucDataBuf)
+{
+ struct atreg_msg_t *patreg_msgdata = (struct atreg_msg_t *)aucDataBuf;
+
+ switch (patreg_msgdata->type) {
+ case AT_REG_SER:
+ atreg_ser_regist_rsp_proc(patreg_msgdata);
+ break;
+
+ case AT_REG_INFO:
+ atreg_info_regist_rsp_proc(patreg_msgdata);
+ break;
+
+ default:
+ break;
+ }
+
+ sem_post(&atreg_common_ctx.sem_id);
+
+ return;
+}
+
+
+static void atreg_ser_unregist_rsp_proc(struct atreg_msg_t *patreg_msgdata)
+{
+ int i = -1;
+ int j = -1;
+ struct atreg_ser_instance_t *patreg_ser_instance = NULL;
+
+ if (0 == patreg_msgdata->res) {
+ patreg_ser_instance = (struct atreg_ser_instance_t *)atreg_search_instance_by_prefix(patreg_msgdata->at_cmd_prefix, AT_REG_SER);
+ if (NULL != patreg_ser_instance) {
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_idpool_lock);
+ i = patreg_ser_instance->req_msg_id / 8;
+ j = patreg_ser_instance->req_msg_id % 8;
+ atreg_ser_dynamic_idpool[i] = atreg_ser_dynamic_idpool[i] & (~(1 << (7 - j)));
+ atreg_ser_dynamic_idpool[i] = atreg_ser_dynamic_idpool[i] & (~(1 << (6 - j)));
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_idpool_lock);
+
+ pthread_mutex_lock(&atreg_ser_ctx.at_ser_lock);
+ list_del((struct list_head *)patreg_ser_instance);
+ pthread_mutex_unlock(&atreg_ser_ctx.at_ser_lock);
+
+ free(patreg_ser_instance);
+
+ slog(ATREG_PRINT, SLOG_NORMAL, "AT %s unregist success!\n", patreg_msgdata->at_cmd_prefix);
+ }
+ } else {
+ slog(ATREG_PRINT, SLOG_ERR, "AT %s unregist fail!\n", patreg_msgdata->at_cmd_prefix);
+ }
+
+ return;
+}
+
+
+static void atreg_info_unregist_rsp_proc(struct atreg_msg_t *patreg_msgdata)
+{
+ int i = -1;
+ int j = -1;
+ struct atreg_info_instance_t *patreg_info_instance = NULL;
+
+ if (0 == patreg_msgdata->res) {
+ patreg_info_instance = (struct atreg_info_instance_t *)atreg_search_instance_by_prefix(patreg_msgdata->at_cmd_prefix, AT_REG_INFO);
+ if (NULL != patreg_info_instance) {
+ pthread_mutex_lock(&atreg_info_ctx.at_info_idpool_lock);
+ i = (patreg_info_instance->req_msg_id - 512) / 8;
+ j = (patreg_info_instance->req_msg_id -512) % 8;
+ atreg_info_dynamic_idpool[i] = atreg_info_dynamic_idpool[i] & (~(1 << (7 - j)));
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_idpool_lock);
+
+ pthread_mutex_lock(&atreg_info_ctx.at_info_lock);
+ list_del((struct list_head *)patreg_info_instance);
+ pthread_mutex_unlock(&atreg_info_ctx.at_info_lock);
+
+ free(patreg_info_instance);
+
+ slog(ATREG_PRINT, SLOG_NORMAL, "AT %s unregist success!\n", patreg_msgdata->at_cmd_prefix);
+ }
+ } else {
+ slog(ATREG_PRINT, SLOG_ERR, "AT %s unregist fail!\n", patreg_msgdata->at_cmd_prefix);
+ }
+
+ return;
+}
+
+
+static void atreg_unregist_rsp_proc(unsigned char *aucDataBuf)
+{
+ struct atreg_msg_t *patreg_msgdata = (struct atreg_msg_t *)aucDataBuf;
+
+ switch (patreg_msgdata->type) {
+ case AT_REG_SER:
+ atreg_ser_unregist_rsp_proc(patreg_msgdata);
+ break;
+
+ case AT_REG_INFO:
+ atreg_info_unregist_rsp_proc(patreg_msgdata);
+ break;
+
+ default:
+ break;
+ }
+
+ sem_post(&atreg_common_ctx.sem_id);
+
+ return;
+}
+
+
+static void atreg_ser_cb_proc(void *patreg_instance, unsigned char *aucDataBuf)
+{
+ int send_ret = -1;
+ unsigned char res_msg[MAX_MSG_LEN] = {0};
+ struct atreg_ser_instance_t *patreg_ser_instance = (struct atreg_ser_instance_t *)patreg_instance;
+
+ patreg_ser_instance->cb(aucDataBuf, res_msg);
+
+ send_ret = ipc_send_message2(atreg_common_ctx.modid, MODULE_ID_AT_CTL, patreg_ser_instance->rsp_msg_id, sizeof(res_msg), (unsigned char *)res_msg, 0);
+ if (0 != send_ret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_ser_cb_proc ipc fail!\n");
+ }
+
+ return;
+}
+
+
+static void atreg_info_cb_proc(void *patreg_instance, unsigned char *aucDataBuf)
+{
+ struct atreg_info_instance_t *patreg_info_instance = (struct atreg_info_instance_t *)patreg_instance;
+
+ patreg_info_instance->cb(aucDataBuf);
+
+ return;
+}
+
+
+static void atreg_cb_proc(int req_msg_id, unsigned char *aucDataBuf)
+{
+ struct atreg_instance_and_type_t atreg_instance_and_type = {0};
+
+ atreg_instance_and_type = atreg_search_instance_and_type_by_reqid(req_msg_id);
+
+ switch (atreg_instance_and_type.type) {
+ case AT_REG_SER:
+ atreg_ser_cb_proc(atreg_instance_and_type.instance, aucDataBuf);
+ break;
+
+ case AT_REG_INFO:
+ atreg_info_cb_proc(atreg_instance_and_type.instance, aucDataBuf);
+ break;
+
+ default:
+ break;
+ }
+
+ return;
+}
+
+
+static void atreg_msg_proc(MSG_BUF *msg)
+{
+ if(NULL == msg) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_msg_proc the msg is NULL!\n");
+ return;
+ }
+
+ switch(msg->usMsgCmd) {
+ case MSG_CMD_AT_REG_RSP:
+ atreg_regist_rsp_proc(msg->aucDataBuf);
+ break;
+
+ case MSG_CMD_AT_UNREG_RSP:
+ atreg_unregist_rsp_proc(msg->aucDataBuf);
+ break;
+
+ default:
+ atreg_cb_proc(msg->usMsgCmd, msg->aucDataBuf);
+ break;
+ }
+
+ return;
+}
+
+
+/*******************************************************************************
+ * Global function implementations *
+ *******************************************************************************/
+/** ¸ÃÏ̴߳´½¨Ö®ºó£¬½«²»»áÍ˳ö */
+void atreg_msg_thread_entry(void *arg)
+{
+ struct atreg_common_context_t *patreg_common_ctx = (struct atreg_common_context_t *)arg;
+ int imsgq = -1;
+ int iret = 0;
+ MSG_BUF msgbuf;
+ long msgsize = sizeof(MSG_BUF) - sizeof(long);
+ char name[32] = {0};
+
+ if(NULL == patreg_common_ctx) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: at_thread_entry the arg is NULL!\n");
+ return;
+ }
+
+ snprintf(name, 31, "atreg%d", patreg_common_ctx->modid);
+ prctl(PR_SET_NAME, name, 0, 0, 0);
+
+ /* ´´½¨atregÏûÏ¢¶ÓÁÐ */
+ imsgq = msgget(patreg_common_ctx->modid, IPC_CREAT|0600);
+ if (-1 == imsgq) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_thread_entry msgget fail!\n");
+ return;
+ }
+
+ while(1) {
+ memset(&msgbuf, 0, sizeof(MSG_BUF));
+
+ iret = msgrcv(imsgq, &msgbuf, msgsize, 0, 0);
+ if (-1 == iret) {
+ slog(ATREG_PRINT, SLOG_ERR, "Err: atreg_thread_entry msgrcv errno=%s\n", errno);
+ continue;
+ }
+ atreg_msg_proc(&msgbuf);
+ }
+
+ slog(ATREG_PRINT, SLOG_NORMAL, "atreg_thread_entry the thread is stop!\n");
+}
+