Add basic change for v1453
Change-Id: I9497a61bbc3717f66413794a4e7dee0347c0bc33
diff --git a/mbtk/test/others/Makefile b/mbtk/test/others/Makefile
new file mode 100755
index 0000000..e6071fb
--- /dev/null
+++ b/mbtk/test/others/Makefile
@@ -0,0 +1,34 @@
+BUILD_ROOT = $(shell pwd)/../..
+include $(BUILD_ROOT)/Make.defines
+
+INC_DIR +=
+
+LIB_DIR +=
+
+LIBS += -lmbtk_lib -laudio-apu -lcutils -ltinyalsa -lacm -lubus -lubox
+
+CFLAGS = $(CFLAGS_TEST)
+
+DEFINE +=
+
+LOCAL_SRC_FILES = $(wildcard *.c) $(wildcard *.cpp)
+
+$(info LOCAL_SRC_FILES = $(LOCAL_SRC_FILES))
+
+OBJS = $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(LOCAL_SRC_FILES)))
+BINS = $(patsubst %.o,%,$(OBJS))
+
+all: $(BINS)
+
+$(BINS):$(OBJS)
+ @echo " BIN $@"
+ $(CC) $(CFLAGS) $(LIB_DIR) $(LIBS) $@.o -o $(OUT_DIR)/bin/$@
+
+%.o:%.c
+ $(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+%.o:%.cpp
+ $(CC) $(CFLAGS) $(INC_DIR) $(DEFINE) -c $< -o $@
+
+clean:
+ rm -f $(OBJS)
diff --git a/mbtk/test/others/fb_demo.c b/mbtk/test/others/fb_demo.c
new file mode 100755
index 0000000..e160edf
--- /dev/null
+++ b/mbtk/test/others/fb_demo.c
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "mbtk_log.h"
+#include "mbtk_type.h"
+
+// RGB565
+#define COLOR_BLACK 0x0000
+#define COLOR_WRITE 0xFFFF
+#define DEV_FB_PATH "/dev/fb0"
+#define SCREEN_WIDTH 320
+#define SCREEN_HEIGTH 240
+
+typedef struct {
+ int left;
+ int top;
+ int width;
+ int heigth;
+} rect_t;
+
+static uint16 fb_buffer[SCREEN_WIDTH * SCREEN_HEIGTH];
+
+static int fb_refresh(int fd)
+{
+ rect_t rect;
+ rect.width = SCREEN_WIDTH / 2;
+ rect.heigth = SCREEN_HEIGTH / 2;
+ rect.left = (SCREEN_WIDTH - rect.width) / 2;
+ rect.top = (SCREEN_HEIGTH - rect.heigth) / 2;
+ // Fill in buffer.
+ int x,y;
+ for(y = 0; y < SCREEN_HEIGTH; y++) {
+ for(x = 0; x < SCREEN_WIDTH; x++) {
+ if(x >= rect.left && x <= rect.left + rect.width
+ && y >= rect.top && y <= rect.top + rect.heigth)
+ {
+ fb_buffer[x * SCREEN_HEIGTH + y] = COLOR_WRITE;
+ } else {
+ fb_buffer[x * SCREEN_HEIGTH + y] = COLOR_BLACK;
+ }
+ }
+ }
+
+ int len = write(fd, fb_buffer, sizeof(fb_buffer));
+ LOGD("Write : %d/%d", len, sizeof(fb_buffer));
+ // Write buffer to framebuffer.
+ if(sizeof(fb_buffer) != len) {
+ LOGE("Write fail:%d", errno);
+ return -1;
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ if(access(DEV_FB_PATH, F_OK) != 0) {
+ LOGE("no %s, quit.", DEV_FB_PATH);
+ return -1;
+ }
+
+ int fb_fd = open(DEV_FB_PATH, O_RDWR);
+ if(fb_fd < 0) {
+ LOGE("open() fail:%d", errno);
+ return -1;
+ }
+
+ // Fresh framebuffer
+ while(1) {
+ if(fb_refresh(fb_fd)) {
+ break;
+ }
+
+ usleep(33); // 1000 / 30
+ }
+
+ LOGD("Exit");
+ return 0;
+}
+
+
diff --git a/mbtk/test/others/framebuffer_demo.c b/mbtk/test/others/framebuffer_demo.c
new file mode 100755
index 0000000..bc35a07
--- /dev/null
+++ b/mbtk/test/others/framebuffer_demo.c
@@ -0,0 +1,285 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <linux/fb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <math.h>
+
+#include "mbtk_utils.h"
+
+/**< \brief 根据实际情况修改,此处为unsigned short是565的屏,根据程序打印出的
+ bits_per_pixel的值可以判断出输出格式是565还是888 */
+// typedef unsigned int color_t;
+typedef unsigned short color_t;
+/**< \brief 定义每个像素点对应的位数,如果是565的屏则为16,如果是888的屏则为32 */
+// #define BITS_PER_PIXEL 32
+#define BITS_PER_PIXEL 16
+
+static struct fb_var_screeninfo __g_vinfo; /* 显示信息 */
+color_t *__gp_frame; /* 虚拟屏幕首地址 */
+
+#pragma pack(2)
+typedef unsigned short WORD;
+typedef unsigned char BYTE;
+typedef unsigned int DWORD;
+typedef int LONG;
+
+typedef struct tagBITMAPFILEHEADER
+{
+ WORD bfType; // 位图文件的类型,必须为BM
+ DWORD bfSize; // 位图文件的大小,以字节为单位
+ WORD bfReserved1; // 位图文件保留字,必须为0
+ WORD bfReserved2; // 位图文件保留字,必须为0
+ DWORD bfOffBits; // 位图数据的起始位置,以相对于位图
+ // 文件头的偏移量表示,以字节为单位
+} BITMAPFILEHEADER;
+
+typedef struct tagBITMAPINFOHEADER
+{
+ DWORD biSize; // 本结构所占用字节数
+ LONG biWidth; // 位图的宽度,以像素为单位
+ LONG biHeight; // 位图的高度,以像素为单位
+ WORD biPlanes; // 目标设备的级别,必须为1
+ WORD biBitCount;// 每个像素所需的位数,必须是1(双色),
+ // 4(16色),8(256色)或24(真彩色)之一
+ DWORD biCompression; // 位图压缩类型,必须是 0(不压缩),
+ // 1(BI_RLE8压缩类型)或2(BI_RLE4压缩类型)之一
+ DWORD biSizeImage; // 位图的大小,以字节为单位
+ LONG biXPelsPerMeter; // 位图水平分辨率,每米像素数
+ LONG biYPelsPerMeter; // 位图垂直分辨率,每米像素数
+ DWORD biClrUsed;// 位图实际使用的颜色表中的颜色数
+ DWORD biClrImportant;// 位图显示过程中重要的颜色数
+} BITMAPINFOHEADER;
+#pragma pack(0)
+
+typedef WORD (*bmp_xx_to_16)(char *);
+
+//画点
+void draw_point(int x, int y, color_t color)
+{
+ color_t *p = __gp_frame;
+
+ p += __g_vinfo.xres * y + x;
+ *p = color;
+}
+
+WORD bmp_24_to_16(char *input)
+{
+ /* 如果使用的bmp图片的颜色深度是24位,适用于888的屏,但如果一定要在565的屏
+ 上显示,则取红色的高5位,绿色的高6位和蓝色的高5位,拼成16位的数据
+ 进行显示。这样做并不是最好的办法,更好的方法是将需要丢失的部分数
+ 据进行进位或舍去。
+ */
+ WORD c;
+ char b, g, r;
+ r = *input >> 3;
+ input++;
+ g = *input >> 2;
+ input++;
+ b = *input >> 3;
+
+ c = (b << 11) | (g << 5) | r;
+
+ return c;
+}
+
+WORD bmp_16_to_16(char *input)
+{
+ WORD c;
+
+ c = *input;
+ input++;
+ c = (c << 8) | *input;
+ c = ((c >> 8) & 0x00ff) | ((c & 0x00ff) << 8);
+
+ return c;
+}
+
+//功能:在指定坐标显示指定BPM24位图
+//参数:(x , y)坐标
+// pic:24位BMP图像
+void Show_BMP(int x , int y , const char *pic)
+{
+ int fd = 0;
+ color_t c;
+ BITMAPFILEHEADER filehead;
+ BITMAPINFOHEADER infohead;
+ int i,j;
+ unsigned char pixel_byte;
+ unsigned char *p = NULL , *p_data = NULL;
+ int width_error = 0;
+ short* t_data = NULL;
+ bmp_xx_to_16 transform_func = NULL;
+ int index = 0;
+
+ printf("%s: %s\n", __FUNCTION__, pic);
+ fd = open(pic , O_RDONLY);
+ if(fd == -1) {
+ printf("fail to open\n");
+ return;
+ }
+
+ mbtk_read(fd , &filehead , sizeof(filehead));
+ mbtk_read(fd , &infohead , sizeof(infohead));
+ printf("bfType: 0x%x, bfSize: %d, bfOffBits: 0x%x\n", filehead.bfType, filehead.bfSize, filehead.bfOffBits);
+
+ printf("biSize: %d, biWidth: %d, biHeight: %d\n", infohead.biSize, infohead.biWidth, infohead.biHeight);
+ printf("biPlanes: %d, biBitCount: %d, biCompression: %d\n", infohead.biPlanes, infohead.biBitCount, infohead.biCompression);
+ printf("biSizeImage: %d, biXPelsPerMeter: %d, biYPelsPerMeter: %d\n", infohead.biSizeImage, infohead.biXPelsPerMeter, infohead.biYPelsPerMeter);
+
+ width_error = (4 - infohead.biWidth * 3 % 4) % 4;
+ pixel_byte = infohead.biBitCount / 8;
+
+ if (16 == infohead.biBitCount) {
+ transform_func = bmp_16_to_16;
+ } else if (24 == infohead.biBitCount) {
+ transform_func = bmp_24_to_16;
+ } else {
+ printf("Not Suppurt %d bmp\n", infohead.biBitCount);
+ close(fd);
+ return;
+ }
+
+ t_data = malloc(__g_vinfo.xres_virtual * __g_vinfo.yres_virtual * __g_vinfo.bits_per_pixel / 8);
+
+ if(t_data == NULL) {
+ perror("fail to malloc");
+ }
+
+ p_data = malloc(infohead.biSizeImage);
+ if(p_data == NULL) {
+ perror("fail to malloc");
+ }
+
+ printf("biSizeImage:%d, width_error: %d\n", infohead.biSizeImage, width_error);
+ mbtk_read(fd , p_data , infohead.biSizeImage);
+ p = p_data;
+
+ int ret;
+ char data[100] = {0};
+ int debug_fd = open("/data/debug_fb", O_RDWR|O_CREAT|O_TRUNC, 0644);
+ if (debug_fd < 0) {
+ printf("debug_fb open error\n");
+ return;
+ }
+ printf("height:%d, width:%d\n", infohead.biHeight, infohead.biWidth);
+ for(j = infohead.biHeight - 1; j >= 0; j--) {
+ for(i = 0; i < infohead.biWidth; i++) {
+ c = transform_func((char*)p);
+ // c = *p;
+ p += pixel_byte;
+ // c = ((c >> 8) & 0x00ff) | ((c & 0x00ff) << 8);
+ t_data[__g_vinfo.xres * (y + j) + (x + i)] = c;
+ // draw_point(x + i, y + j, c);
+ index++;
+
+ sprintf(data, "index:%d, i:%d, j:%d\n", index, i, j);
+ ret = write(debug_fd, data, strlen(data));
+ if (ret < 0) {
+ printf("%s write error\n", __FUNCTION__);
+ }
+ }
+ p += width_error;
+ }
+ close(debug_fd);
+ printf("%s: %d\n", __FUNCTION__, infohead.biHeight * infohead.biWidth * __g_vinfo.bits_per_pixel / 8);
+ memcpy(__gp_frame, t_data,
+ infohead.biHeight * infohead.biWidth * __g_vinfo.bits_per_pixel / 8);
+ printf("%s: %d\n", __FUNCTION__, index);
+ free(p_data);
+ free(t_data);
+ close(fd);
+}
+
+/**
+ * \brief 填充整屏
+ */
+void full_screen (color_t color)
+{
+ int i;
+ color_t *p = __gp_frame;
+
+ for (i = 0; i < __g_vinfo.xres_virtual * __g_vinfo.yres_virtual; i++) {
+ *p++ = color;
+ }
+}
+
+/**
+ * \brief 清屏
+ */
+void clear()
+{
+ full_screen(0);
+}
+
+/* framebuffer初始化 */
+int framebuffer_init (void)
+{
+ int fd = 0;
+
+ fd = open("/dev/fb0", O_RDWR);
+ if (fd == -1) {
+ perror("fail to open /dev/fb0\n");
+ return -1;
+ }
+
+ /* 获取显示信息 */
+ ioctl(fd, FBIOGET_VSCREENINFO, &__g_vinfo); /* 获取显示信息 */
+ printf("bits_per_pixel = %d\n", __g_vinfo.bits_per_pixel); /* 得到一个像素点对应的位数 */
+ printf("xres_virtual = %d\n", __g_vinfo.xres_virtual); /* 打印虚拟屏幕列数 */
+ printf("yres_virtual = %d\n", __g_vinfo.yres_virtual); /* 打印虚拟屏幕行数 */
+ printf("xres = %d\n", __g_vinfo.xres); /* 打印屏幕列数 */
+ printf("yres = %d\n", __g_vinfo.yres); /* 打印屏幕行数 */
+
+ int len = __g_vinfo.xres_virtual * __g_vinfo.yres_virtual * __g_vinfo.bits_per_pixel / 8; /* 映射区大小 */
+
+ printf("fb size = %d\n", len);
+ __gp_frame = mmap(NULL, /* 映射区的开始地址,为NULL表示由系统决定映射区的起始地址 */
+ len,
+ PROT_WRITE | PROT_READ, /* 内存保护标志(可读可写) */
+ MAP_SHARED, /* 映射对象类型(与其他进程共享) */
+ fd, /* 有效的文件描述符 */
+ 0); /* 被映射内容的偏移量 */
+ if (__gp_frame == NULL) {
+ perror("fail to mmap\n");
+ return -1;
+ }
+
+ return fd;
+}
+
+
+int main(int argc, const char *argv[])
+{
+ int fd;
+
+ if (argc < 2) {
+ printf("%s \" img \"", argv[0]);
+ exit(1);
+ }
+
+ fd = framebuffer_init();
+ if (fd < 0) {
+ printf("framebuffer_init error\n");
+ return 0;
+ }
+
+ printf("framebuffer_init Success.\n");
+ /* 清屏 */
+ clear();
+
+ printf("clear Success.\n");
+
+ // full_screen(0xF800); // 显示红色
+
+ Show_BMP(0 , 0 , argv[1]);
+
+ close(fd);
+
+ return 0;
+}
diff --git a/mbtk/test/others/fs_full.c b/mbtk/test/others/fs_full.c
new file mode 100755
index 0000000..cb53e49
--- /dev/null
+++ b/mbtk/test/others/fs_full.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#define BUFF_SIZE 4096
+
+int main(int argc, char *argv[])
+{
+ int fd = open("/test.data", O_WRONLY | O_CREAT | O_APPEND, 0666);
+ if(fd < 0) {
+ printf("open() fail:%d", errno);
+ return -1;
+ }
+
+ char buff[BUFF_SIZE];
+ while(1) {
+ if(write(fd, buff, BUFF_SIZE) < 0) {
+ printf("write() fail:%d", errno);
+ break;
+ }
+ }
+
+ close(fd);
+ return 0;
+}
+
diff --git a/mbtk/test/others/iconv_demo.cc b/mbtk/test/others/iconv_demo.cc
new file mode 100755
index 0000000..de95454
--- /dev/null
+++ b/mbtk/test/others/iconv_demo.cc
@@ -0,0 +1,204 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <iconv.h>
+#include <errno.h>
+#include <stddef.h>
+
+struct outbuf
+{
+ struct outbuf *next;
+ char *outptr;
+ size_t outbytesleft;
+ char buf[256];
+};
+
+char *eazyiconv(const char *to, const char *from,
+ char *str, size_t str_blen, size_t str_elemsize, size_t out_tailzero_blen, size_t *out_size,
+ const char *replchr)
+{
+ char *retstr = NULL;
+ struct outbuf *outhead = NULL;
+ struct outbuf *outtail = NULL;
+ struct outbuf *outiter = NULL;
+ iconv_t cd = NULL;
+ char *inptr = str;
+ size_t inbytesleft = str_blen;
+ int retval = 0;
+ int err = 0;
+ size_t blocksize = 0;
+ size_t totalsize = 0;
+ char *retiter = NULL;
+ unsigned int chrval = 0;
+ iconv_t cdreplchr = NULL;
+ char replchrfmtbuf[256] = "";
+ char replchrbuf[256] = "";
+ char *replchrfmtptr = replchrfmtbuf;
+ size_t replchrfmtleft = sizeof replchrfmtbuf;
+ char *replchrptr = replchrbuf;
+ size_t replchrleft = sizeof replchrbuf;
+ int replchr_blen = 0;
+
+ cd = iconv_open(to, from);
+ if (cd == (iconv_t)-1)
+ {
+ goto noclean;
+ }
+
+ outhead = outtail = calloc(1, sizeof(struct outbuf));
+ if (outtail == NULL)
+ {
+ goto clean_cd;
+ }
+ outtail->next = NULL;
+ outtail->outptr = outtail->buf;
+ outtail->outbytesleft = sizeof outtail->buf;
+ memset(outtail->buf, 0, sizeof outtail->buf);
+
+ while (1)
+ {
+ retval = iconv(cd, &inptr, &inbytesleft, &outtail->outptr, &outtail->outbytesleft);
+ if (retval == -1)
+ err = errno;
+ else
+ err = 0;
+ switch (err)
+ {
+ case 0:
+ outiter = calloc(1, sizeof(struct outbuf));
+ if (outiter == NULL)
+ {
+ goto clean_outbufs;
+ }
+ if (inptr == NULL) // succeeded cleanup iconv
+ {
+ goto succeeded;
+ }
+ else // fully succeeded iconv
+ {
+ inptr = NULL; // do cleanup iconv
+ inbytesleft = 0;
+ }
+ break;
+ case EINVAL: // incomplete tail sequence
+ case EILSEQ: // invalid sequence
+ chrval = 0;
+ memcpy(&chrval, inptr, str_elemsize > sizeof chrval ? sizeof chrval : str_elemsize);
+ snprintf(replchrfmtbuf, sizeof replchrfmtbuf, replchr, chrval);
+ inptr += str_elemsize;
+ inbytesleft -= str_elemsize;
+
+ cdreplchr = iconv_open(to, "UTF-8");
+ if (cdreplchr == (iconv_t)-1)
+ {
+ goto clean_outbufs;
+ }
+ replchrfmtptr = replchrfmtbuf;
+ replchrfmtleft = strlen(replchrfmtbuf);
+ replchrptr = replchrbuf;
+ replchrleft = sizeof replchrbuf;
+ iconv(cdreplchr, &replchrfmtptr, &replchrfmtleft, &replchrptr, &replchrleft);
+ iconv(cdreplchr, NULL, NULL, &replchrptr, &replchrleft);
+ iconv_close(cdreplchr);
+ replchr_blen = replchrptr - replchrbuf;
+
+ if (outtail->outbytesleft < replchr_blen)
+ {
+ outiter = calloc(1, sizeof(struct outbuf));
+ if (outiter == NULL)
+ {
+ goto clean_outbufs;
+ }
+ outtail->next = outiter;
+ outtail = outiter;
+ outtail->next = NULL;
+ outtail->outptr = outtail->buf;
+ outtail->outbytesleft = sizeof outtail->buf;
+ memset(outtail->buf, 0, sizeof outtail->buf);
+ }
+ memcpy(outtail->outptr, replchrbuf, replchr_blen);
+ outtail->outptr += replchr_blen;
+ outtail->outbytesleft -= replchr_blen;
+ break;
+ case E2BIG: // no enough space
+ outiter = calloc(1, sizeof(struct outbuf));
+ if (outiter == NULL)
+ {
+ goto clean_outbufs;
+ }
+ outtail->next = outiter;
+ outtail = outiter;
+ outtail->next = NULL;
+ outtail->outptr = outtail->buf;
+ outtail->outbytesleft = sizeof outtail->buf;
+ memset(outtail->buf, 0, sizeof outtail->buf);
+ break;
+ default:
+ break;
+ }
+ }
+
+succeeded:
+ totalsize = 0;
+ for (outiter = outhead; outiter != NULL; outiter = outiter->next)
+ {
+ blocksize = outiter->outptr - outiter->buf;
+ totalsize += blocksize;
+ }
+ retstr = calloc(totalsize + out_tailzero_blen, 1);
+ if (retstr == NULL)
+ {
+ goto clean_outbufs;
+ }
+ retiter = retstr;
+ for (outiter = outhead; outiter != NULL; outiter = outiter->next)
+ {
+ blocksize = outiter->outptr - outiter->buf;
+ memcpy(retiter, outiter->buf, blocksize);
+ retiter += blocksize;
+ }
+ memset(retiter, 0, out_tailzero_blen);
+ *out_size = totalsize;
+
+clean_outbufs:
+ while (outhead != NULL)
+ {
+ outiter = outhead;
+ outhead = outhead->next;
+ free(outiter);
+ }
+ outtail = NULL;
+clean_cd:
+ iconv_close(cd);
+noclean:
+ return retstr;
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 7)
+ {
+ printf("usage: eiconv_test from_charset from_elemsize to_charset to_elemsize from_file to_file (no utf-16/32)\n");
+ return 0;
+ }
+ FILE *from_file = fopen(argv[5], "rb");
+ fseek(from_file, 0, SEEK_END);
+ off_t fsize = ftell(from_file);
+ fseek(from_file, 0, SEEK_SET);
+ char *from_str = malloc(fsize + 1);
+ fread(from_str, 1, fsize, from_file);
+ fclose(from_file);
+
+ size_t out_size = 0;
+ char *to_str = eazyiconv(argv[3], argv[1],
+ from_str, fsize, atoi(argv[2]), atoi(argv[4]), &out_size,
+ "<0x%02X>");
+
+ FILE *to_file = fopen(argv[6], "wb");
+ fwrite(to_str, 1, out_size, to_file);
+ free(to_str);
+ fclose(to_file);
+ return 0;
+}
+
+
diff --git a/mbtk/test/others/mbtk_debug_test.c b/mbtk/test/others/mbtk_debug_test.c
new file mode 100755
index 0000000..39c8105
--- /dev/null
+++ b/mbtk/test/others/mbtk_debug_test.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <pthread.h>
+
+#include "mbtk_log.h"
+#include "mbtk_utils.h"
+
+
+void test3()
+{
+ printf("%s start\n", __FUNCTION__);
+ char *ptr = (char*)10;
+ *ptr = 'a';
+ printf("%s end\n", __FUNCTION__);
+}
+
+void test2()
+{
+ printf("%s start\n", __FUNCTION__);
+ mbtk_get_kernel_cmdline(NULL, 1024);
+ // test3();
+ printf("%s end\n", __FUNCTION__);
+}
+
+void test1()
+{
+ printf("%s start\n", __FUNCTION__);
+ test2();
+ printf("%s end\n", __FUNCTION__);
+}
+
+void* thread_function(void* arg) {
+ // 模拟一个导致SIGSEGV的操作
+ int* invalid_pointer = NULL;
+ *invalid_pointer = 0; // 尝试写入一个无效的指针,将触发SIGSEGV
+ return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+
+#ifdef MBTK_DUMP_SUPPORT
+ mbtk_debug_open(NULL, TRUE);
+#endif
+
+ test1();
+
+ pthread_t thread;
+ pthread_create(&thread, NULL, &thread_function, NULL);
+ pthread_join(thread, NULL);
+
+ printf("Exit.\n");
+
+ return 0;
+}
+
diff --git a/mbtk/test/others/mbtk_gnss_cli.c b/mbtk/test/others/mbtk_gnss_cli.c
new file mode 100755
index 0000000..825d501
--- /dev/null
+++ b/mbtk/test/others/mbtk_gnss_cli.c
@@ -0,0 +1,181 @@
+/*
+* gnss_ipc.c
+*
+* MBTK GNSS IPC service source.
+*
+*/
+/******************************************************************************
+
+ EDIT HISTORY FOR FILE
+
+ WHEN WHO WHAT,WHERE,WHY
+-------- -------- -------------------------------------------------------
+2024/6/15 LiuBin Initial version
+
+******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <pthread.h>
+#include <sys/epoll.h>
+
+#include "mbtk_log.h"
+#include "mbtk_type.h"
+#include "mbtk_gnss.h"
+#include "mbtk_utils.h"
+
+#define GNSS_SOCK_PATH "/tmp/mbtk_gnss_sock"
+
+static int sock_listen_fd = -1;
+
+typedef enum {
+ GNSS_CMD_INIT = 0,
+ GNSS_CMD_DEINIT,
+ GNSS_CMD_SETTING,
+ GNSS_CMD_DL
+} gnss_cmd_enum;
+
+static void help()
+{
+ printf("gnss_cli gnss_init <0-15>\n");
+ printf("gnss_cli gnss_deinit\n");
+ printf("gnss_cli gnss_setting cmd\n");
+ printf("gnss_cli gnss_dl fw_name\n");
+}
+
+static int cmd_process(gnss_cmd_enum cmd, void *arg)
+{
+ if(sock_listen_fd < 0) {
+ sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+ if(sock_listen_fd < 0)
+ {
+ printf("socket() fail[%d].\n", errno);
+ return -1;
+ }
+
+ struct sockaddr_un cli_addr;
+ memset(&cli_addr, 0, sizeof(cli_addr));
+ cli_addr.sun_family = AF_LOCAL;
+ strcpy(cli_addr.sun_path, GNSS_SOCK_PATH);
+ if(connect(sock_listen_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)))
+ {
+ printf("connect() fail[%d].\n", errno);
+ close(sock_listen_fd);
+ sock_listen_fd = -1;
+ return -1;
+ }
+ }
+
+ char buff[100] = {0};
+ if(cmd == GNSS_CMD_INIT) {
+ if(arg) {
+ int type = atoi((char*)arg);
+ sprintf(buff, "gnss_init:%d", type);
+ } else {
+ return -1;
+ }
+ } else if(cmd == GNSS_CMD_DEINIT) {
+ sprintf(buff, "gnss_deinit");
+ } else if(cmd == GNSS_CMD_SETTING) {
+ sprintf(buff, "gnss_setting:%s", (char*)arg);
+ } else if(cmd == GNSS_CMD_DL) {
+ sprintf(buff, "gnss_dl:%s", (char*)arg);
+ } else {
+ printf("Unknown cmd.\n");
+ return -1;
+ }
+
+ mbtk_write(sock_listen_fd, buff, strlen(buff));
+
+ int len = 0;
+ char *rsp = NULL;
+ while(1) {
+ memset(buff, 0, sizeof(buff));
+ len = read(sock_listen_fd, buff, sizeof(buff));
+ if(len > 0) {
+ rsp = buff;
+ if(rsp[len - 1] == MBTK_IND_END_FLAG) {
+ rsp[len - 1] = '\0';
+ }
+ if(rsp[0] == MBTK_IND_START_FLAG) {
+ rsp++;
+ }
+ printf("RSP : %s\n", rsp);
+ if(cmd == GNSS_CMD_INIT) {
+ if(memcmp(rsp, "gnss_init", 9) == 0) {
+ return atoi(rsp + 10);
+ } else {
+ printf("gnss_init response error.\n");
+ return -1;
+ }
+ } else if(cmd == GNSS_CMD_DEINIT) {
+ if(memcmp(rsp, "gnss_deinit", 11) == 0) {
+ return atoi(rsp + 12);
+ } else {
+ printf("gnss_deinit response error.\n");
+ return -1;
+ }
+ } else if(cmd == GNSS_CMD_SETTING) {
+ if(memcmp(rsp, "gnss_setting", 12) == 0) {
+ return atoi(rsp + 13);
+ } else {
+ printf("gnss_setting response error.\n");
+ return -1;
+ }
+ } else if(cmd == GNSS_CMD_DL) {
+ if(memcmp(rsp, "gnss_dl", 7) == 0) {
+ return atoi(rsp + 8);
+ } else {
+ printf("gnss_dl response error.\n");
+ return -1;
+ }
+ } else {
+ printf("Unknown response.\n");
+ return -1;
+ }
+ } else if(len == 0) {
+ printf("RSP is null.\n");
+ return -1;
+ } else {
+ printf("read = %d:errno = %d\n", len, errno);
+ }
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+ if(argc == 2) {
+ if(strcmp(argv[1], "gnss_deinit")) {
+ help();
+ return -1;
+ }
+
+ ret = cmd_process(GNSS_CMD_DEINIT, NULL);
+ } else if(argc == 3) {
+ if(strcmp(argv[1], "gnss_init") == 0) {
+ ret = cmd_process(GNSS_CMD_INIT, argv[2]);
+ } else if(strcmp(argv[1], "gnss_setting") == 0) {
+ ret = cmd_process(GNSS_CMD_SETTING, argv[2]);
+ } else if(strcmp(argv[1], "gnss_dl") == 0) {
+ ret = cmd_process(GNSS_CMD_DL, argv[2]);
+ } else {
+ help();
+ return -1;
+ }
+ } else {
+ help();
+ return -1;
+ }
+
+ // printf("Error:%s\n", strerror(EBADF));
+
+ printf("Result : %d\n", ret);
+ return 0;
+}
+
diff --git a/mbtk/test/others/mbtk_mbedtls_demo.c b/mbtk/test/others/mbtk_mbedtls_demo.c
new file mode 100755
index 0000000..45909ae
--- /dev/null
+++ b/mbtk/test/others/mbtk_mbedtls_demo.c
@@ -0,0 +1,162 @@
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @file NULL
+ @brief libmbedtls.so.3.6.2 function test
+*/
+/*-----------------------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------------------------
+ Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
+ mobiletek Wireless Solution Proprietary and Confidential.
+-------------------------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------------------------
+ EDIT HISTORY
+ This section contains comments describing changes made to the file.
+ Notice that changes are listed in reverse chronological order.
+ $Header: $
+ when who what, where, why
+ -------- --------- -----------------------------------------------------------------
+ 20241022 yq.wang Created .
+-------------------------------------------------------------------------------------------------*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+#ifdef MBTK_MBEDTLS_V3_6_2_SUPPORT
+#include "mbtk_mbedtls.h"
+
+#define BUFFER_SIZE 1024
+
+static int tcp_connect_init(int *client_fd, int port, char *ip)
+{
+ int ret = -1;
+ struct sockaddr_in server_addr;
+
+ if(port < 1 || port > 65535)
+ {
+ printf("[%s] Invalid port number\n", __func__);
+ goto error;
+ }
+
+ *client_fd = socket(AF_INET, SOCK_STREAM, 0);
+ if(*client_fd < 0)
+ {
+ printf("[%s] socket creation failed\n", __func__);
+ goto error;
+ }
+
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = htons(port);
+ ret = inet_pton(AF_INET, ip, &server_addr.sin_addr);
+ if(ret <= 0)
+ {
+ perror("invalid address");
+ goto error;
+ }
+
+ ret = connect(*client_fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
+ if(ret< 0)
+ {
+ perror("connection failed");
+ goto error;
+ }
+
+ printf("[%s] Connected to %s:%d\n", __func__, ip, port);
+ return 0;
+error:
+ if(*client_fd >= 0)
+ {
+ close(*client_fd);
+ *client_fd = -1;
+ }
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc != 3)
+ {
+ printf("Usage: %s <IP> <PORT>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ int ret = -1;
+ int client_fd = -1;
+ ssize_t bytes_recv = 0;
+ char buffer[BUFFER_SIZE] = {0};
+ mbtk_mbedtls_ssl_result_e mbtk_ssl_ret = MBTK_MBEDTLS_SSL_RESULT_SUCCESS;
+ mbtk_mbedtls_ssl_info_s inter_info = {0};
+ mbtk_mbedtls_ssl_options_s opt = {0};
+
+ ret = tcp_connect_init(&client_fd, atoi(argv[2]), argv[1]);
+ if(ret < 0)
+ {
+ printf("tcp_connect_init() fail\n");
+ exit(EXIT_FAILURE);
+ }
+
+ mbtk_mbedtls_ssl_options_default(&opt);
+ opt.load_cert = true;
+ opt.ca_file = "/ca.crt";
+ opt.crt_file = "/client.crt";
+ opt.key_file = "/client.key";
+ opt.auth_mode = MBTK_MBEDTLS_SSL_VERIFY_REQUIRED;
+ opt.allowed_mds |= MBTK_MBEDTLS_SSL_MD_SHA1;
+ memset(&inter_info, 0x00, sizeof(mbtk_mbedtls_ssl_info_s));
+ mbtk_ssl_ret = mbtk_mbedtls_ssl_init(client_fd, &opt, &inter_info);
+ if(mbtk_ssl_ret != MBTK_MBEDTLS_SSL_RESULT_SUCCESS)
+ {
+ printf("mbtk_mbedtls_ssl_init() fail\n");
+ close(client_fd);
+ client_fd = -1;
+ exit(EXIT_FAILURE);
+ }
+
+ while(1)
+ {
+ printf("Enter message: \n");
+ fgets(buffer, BUFFER_SIZE, stdin);
+
+ if(memcmp(buffer, "exit", 4) == 0)
+ {
+ printf("process exit\n");
+ break;
+ }
+
+ ret = mbtk_mbedtls_ssl_write(inter_info.ssl, (const unsigned char*)buffer, strlen(buffer));
+ if(ret < 0)
+ {
+ perror("send failed");
+ break;
+ }
+
+ bytes_recv = mbtk_mbedtls_ssl_read(inter_info.ssl, (unsigned char*)buffer, BUFFER_SIZE-1);
+ if (bytes_recv <= 0)
+ {
+ bytes_recv == 0 ? printf("Connection closed\n") : perror("recv failed");
+ break;
+ }
+ buffer[bytes_recv] = '\0';
+ printf("Server response: %s\n", buffer);
+ }
+
+ mbtk_mbedtls_ssl_deinit(&inter_info);
+ close(client_fd);
+ client_fd = -1;
+
+ return 0;
+}
+
+#else
+int main(int argc, char *argv[])
+{
+ printf("No support polarssl.\n");
+ return 0;
+}
+#endif
+
diff --git a/mbtk/test/others/mbtk_mdio_demo.c b/mbtk/test/others/mbtk_mdio_demo.c
new file mode 100755
index 0000000..1a129fb
--- /dev/null
+++ b/mbtk/test/others/mbtk_mdio_demo.c
@@ -0,0 +1,201 @@
+
+//mdio eth0 1 读取phy寄存器1的数值
+//mdio eth0 0 0x1120 将0x1120写入 phy寄存器1
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/mii.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <linux/sockios.h>
+#include <linux/types.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <string.h>
+
+
+#define reteck(ret) \
+ if(ret < 0){ \
+ printf("%m! \"%s\" : line: %d\n", __func__, __LINE__); \
+ goto lab; \
+ }
+
+#define help() \
+ printf("For example:\n"); \
+ printf("mbtk_mdio_demo eth0\n"); \
+ exit(0);
+
+int sockfd;
+
+int main(int argc, char *argv[])
+{
+ int err, value;
+ int cmdIdx = 0;
+ int ret = 0;
+ int i = 0;
+ char operator[10];
+ int opt = 0;
+
+ struct mii_ioctl_data *mii = NULL;
+ struct ifreq ifr;
+
+ if(argc == 1 || !strcmp(argv[1], "-h")){
+ help();
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
+
+ sockfd = socket(PF_LOCAL, SOCK_DGRAM, 0);
+ reteck(sockfd);
+
+ //get phy address in smi bus
+ ret = ioctl(sockfd, SIOCGMIIPHY, &ifr);
+ reteck(ret);
+
+ mii = (struct mii_ioctl_data*)&ifr.ifr_data;
+
+ while(1)
+ {
+
+ printf("=========EX:Jl3103========\n"
+ "\t 0: Set the slave mode\n"
+ "\t 1: Set the master mode\n"
+ "\t 2: indicates setting SQI value view mode\n"
+ "\t 3: Set the VCT value view mode\n"
+ "\t 4: Get slave/master mode\n"
+ "\t 5 EXIT \n"
+ "=========================\n");
+
+ fflush(stdin);
+ fgets(operator, sizeof(operator), stdin);
+ opt = atoi(operator);
+
+ switch(opt)
+ {
+ case 0://"Set the slave mode"
+ {
+ int val = 0;
+ mii->reg_num = 0x0834;
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+ val = mii->val_out;
+
+ mii->reg_num = 0x0834;
+ mii->val_in = val & 0xBFFF;// set bit[14] = 0
+
+ ret = ioctl(sockfd, SIOCSMIIREG, &ifr);
+ reteck(ret);
+
+ printf("write phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_in);
+
+ break;
+ }
+ case 1://"Set the master mode"
+ {
+ int val = 0;
+ mii->reg_num = 0x0834;
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+ val = mii->val_out;
+
+ mii->reg_num = 0x0834;
+ mii->val_in = val | 0x4000;//set bit[14] = 1
+
+ ret = ioctl(sockfd, SIOCSMIIREG, &ifr);
+ reteck(ret);
+
+ printf("write phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_in);
+ break;
+ }
+ case 2://"indicates setting SQI value view mode\"
+ {
+ mii->reg_num = 0x8B10;
+
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+ printf("[Jl3103] SQI is 0x%x\n", mii->val_out);
+ break;
+ }
+ case 3://"Set the VCT value view mode"
+ {
+ mii->reg_num = 0x8B00;
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+
+ //--TDR Enable
+ mii->reg_num = 0x8B00;
+ mii->val_in = 0x4000;
+
+ ret = ioctl(sockfd, SIOCSMIIREG, &ifr);
+ reteck(ret);
+
+ printf("write phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_in);
+ usleep(200000);
+ //--TDR Start
+ mii->reg_num = 0x8B00;
+ mii->val_in = 0x5000;
+
+ ret = ioctl(sockfd, SIOCSMIIREG, &ifr);
+ reteck(ret);
+
+ printf("write phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_in);
+ usleep(20000);
+ //--Read VCT
+ mii->reg_num = 0x8B02;
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+ printf("[Jl3103] Open status: %s - Short status: %s\n", (mii->val_out & 0x0002) ? "Open" : "Normal", (mii->val_out & 0x0001) ? "Short" : "Normal");
+
+ mii->reg_num = 0x8B01;
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+ printf("[Jl3103] Distance status is 0x%x\n", mii->val_out % 0x200);//bits[9:0]
+ //--TDR Disable
+ mii->reg_num = 0x8B00;
+ mii->val_in = 0;
+
+ ret = ioctl(sockfd, SIOCSMIIREG, &ifr);
+ reteck(ret);
+
+ printf("write phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_in);
+ break;
+ }
+ case 4://4: Get slave/master mode
+ {
+ int val = 0;
+ mii->reg_num = 0x0834;
+ ret = ioctl(sockfd, SIOCGMIIREG, &ifr);
+ reteck(ret);
+
+ printf("read phy addr: 0x%x reg: 0x%x value : 0x%x\n", mii->phy_id, mii->reg_num, mii->val_out);
+ printf("[Jl3103] mode: %s\n", (mii->val_out & 0x4000) ? "master" : "slave");
+ break;
+ }
+ default://EXIT
+ {
+ printf("break\n");
+ close(sockfd);
+ return 0;
+ }
+ }
+ }
+lab:
+ close(sockfd);
+ return 0;
+}
\ No newline at end of file
diff --git a/mbtk/test/others/mbtk_openssl_demo.c b/mbtk/test/others/mbtk_openssl_demo.c
new file mode 100755
index 0000000..08ff7b8
--- /dev/null
+++ b/mbtk/test/others/mbtk_openssl_demo.c
@@ -0,0 +1,190 @@
+/*-----------------------------------------------------------------------------------------------*/
+/**
+ @file NULL
+ @brief libssl.so.3 function test
+*/
+/*-----------------------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------------------------
+ Copyright (c) 2024 mobiletek Wireless Solution, Co., Ltd. All Rights Reserved.
+ mobiletek Wireless Solution Proprietary and Confidential.
+-------------------------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------------------------
+ EDIT HISTORY
+ This section contains comments describing changes made to the file.
+ Notice that changes are listed in reverse chronological order.
+ $Header: $
+ when who what, where, why
+ -------- --------- -----------------------------------------------------------------
+ 20250409 yq.wang Created .
+-------------------------------------------------------------------------------------------------*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#ifdef MBTK_OPENSSL_V3_0_0_SUPPORT
+#include "mbtk_openssl.h"
+
+#define BUFFER_SIZE 1024
+
+void* recv_thread(void *arg)
+{
+ mbtk_openssl_info_s *inter_info = (mbtk_openssl_info_s *)(intptr_t)arg;
+ char buffer[BUFFER_SIZE + 1] = {0};
+
+ while(1)
+ {
+ memset(buffer, 0x00, BUFFER_SIZE + 1);
+ ssize_t len = mbtk_openssl_read(inter_info->ssl, buffer, BUFFER_SIZE);
+ if(len <= 0)
+ {
+ if(len == 0)
+ {
+ printf("Connection closed by server\n");
+ }
+ else
+ {
+ printf("mbtk_openssl_read() fail.[%d]\n", len);
+ }
+ break;
+ }
+ buffer[len] = '\0';
+ printf("\nReceived: %s\n", buffer);
+ }
+
+ return NULL;
+}
+
+static int tcp_connect_init(int *client_fd, int port, char *ip)
+{
+ int ret = -1;
+ struct sockaddr_in server_addr;
+
+ if(port < 1 || port > 65535)
+ {
+ printf("[%s] Invalid port number\n", __func__);
+ goto error;
+ }
+
+ *client_fd = socket(AF_INET, SOCK_STREAM, 0);
+ if(*client_fd < 0)
+ {
+ printf("[%s] socket creation failed\n", __func__);
+ goto error;
+ }
+
+ server_addr.sin_family = AF_INET;
+ server_addr.sin_port = htons(port);
+ ret = inet_pton(AF_INET, ip, &server_addr.sin_addr);
+ if(ret <= 0)
+ {
+ perror("invalid address");
+ goto error;
+ }
+
+ ret = connect(*client_fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
+ if(ret< 0)
+ {
+ perror("connection failed");
+ goto error;
+ }
+
+ printf("[%s] Connected to %s:%d\n", __func__, ip, port);
+ return 0;
+error:
+ if(*client_fd >= 0)
+ {
+ close(*client_fd);
+ *client_fd = -1;
+ }
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc != 3)
+ {
+ printf("Usage: %s <IP> <PORT>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ int ret = -1;
+ int client_fd = -1;
+ ssize_t bytes_recv = 0;
+ char buffer[BUFFER_SIZE + 1] = {0};
+ mbtk_openssl_result_e mbtk_ret = MBTK_OPENSSL_RESULT_SUCCESS;
+ mbtk_openssl_info_s inter_info = {0};
+ mbtk_openssl_options_s opt = {0};
+
+ pthread_t tid;
+
+ ret = tcp_connect_init(&client_fd, atoi(argv[2]), argv[1]);
+ if(ret < 0)
+ {
+ printf("tcp_connect_init() fail\n");
+ exit(EXIT_FAILURE);
+ }
+
+ mbtk_openssl_options_default(&opt);
+ opt.load_cert = true;
+ opt.ca_file = "/ca.crt";
+ opt.crt_file = "/client.crt";
+ opt.key_file = "/client.key";
+ opt.safety_level = MBTK_OPENSSL_SAFETY_LEVEL_0;//Use level 0 for testing only
+ mbtk_ret = mbtk_openssl_init(client_fd, &opt, &inter_info);
+ if(mbtk_ret != MBTK_OPENSSL_RESULT_SUCCESS)
+ {
+ printf("mbtk_openssl_init() fail\n");
+ close(client_fd);
+ client_fd =-1;
+ exit(EXIT_FAILURE);
+ }
+
+ ret = pthread_create(&tid, NULL, recv_thread, (void*)(intptr_t)&inter_info);
+ if(ret != 0)
+ {
+ perror("thread creation failed");
+ close(client_fd);
+ client_fd = -1;
+ exit(EXIT_FAILURE);
+ }
+
+ while(1)
+ {
+ printf("Enter message: \n");
+ memset(buffer, 0x00, BUFFER_SIZE);
+ fgets(buffer, BUFFER_SIZE, stdin);
+
+ if(memcmp(buffer, "exit", 4) == 0)
+ {
+ printf("process exit\n");
+ break;
+ }
+
+ ret = mbtk_openssl_write(inter_info.ssl, buffer, strlen(buffer));
+ if(ret < 0)
+ {
+ printf("mbtk_openssl_write() fail.[%d]\n", ret);
+ break;
+ }
+ }
+
+ mbtk_openssl_deinit(&inter_info);
+ close(client_fd);
+ client_fd = -1;
+
+ return 0;
+}
+#else
+int main(int argc, char *argv[])
+{
+ printf("No support openssl.\n");
+ return 0;
+}
+#endif
\ No newline at end of file
diff --git a/mbtk/test/others/mbtk_rtp_udp_cli.c b/mbtk/test/others/mbtk_rtp_udp_cli.c
new file mode 100755
index 0000000..92c19cf
--- /dev/null
+++ b/mbtk/test/others/mbtk_rtp_udp_cli.c
@@ -0,0 +1,373 @@
+#include <stdio.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <sys/epoll.h>
+#include <arpa/inet.h>
+#include <sys/ioctl.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <sys/stat.h>
+
+//#include "mbtk_log.h"
+//#include "mbtk_utils.h"
+// #include "audio_if_api.h"
+//#include "mbtk_audio2.h"
+
+#define RTP_UDP_SER_PORT_DEFAULT 53248
+#define RTP_UDP_CLI_PORT_DEFAULT 55555
+
+
+#define BUFF_SIZE 4096
+
+#define ID_RIFF 0x46464952
+#define ID_WAVE 0x45564157
+#define ID_FMT 0x20746d66
+#define ID_DATA 0x61746164
+#define FORMAT_PCM 1
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#ifndef UNUSED
+#define UNUSED(a) (void)(a)
+#endif
+
+typedef unsigned int uint32; /* Unsigned 32 bit value */
+
+struct riff_wave_header {
+ unsigned int riff_id;
+ unsigned int riff_sz;
+ unsigned int wave_id;
+};
+
+struct chunk_header {
+ unsigned int id;
+ unsigned int sz;
+};
+
+struct chunk_fmt {
+ unsigned short audio_format;
+ unsigned short num_channels;
+ unsigned int sample_rate;
+ unsigned int byte_rate;
+ unsigned short block_align;
+ unsigned short bits_per_sample;
+};
+
+struct wav_header {
+ unsigned int riff_id;
+ unsigned int riff_sz;
+ unsigned int riff_fmt;
+ unsigned int fmt_id;
+ unsigned int fmt_sz;
+ unsigned short audio_format;
+ unsigned short num_channels;
+ unsigned int sample_rate;
+ unsigned int byte_rate;
+ unsigned short block_align;
+ unsigned short bits_per_sample;
+ unsigned int data_id;
+ unsigned int data_sz;
+};
+
+
+#define PCM_WB_BUF_SIZE 640
+#define PCM_NARROW_BUF_SIZE 320
+
+static int record_fd = -1;
+static int send_fd = -1;
+static bool running = FALSE;
+
+
+static void voip_playback_run(void *arg)
+{
+ int rc, len, fd, frames = 0;
+ int pack_size = 320;
+ //char buf[MBTK_PCM_WB_BUF_SIZE];
+ char buf[BUFF_SIZE];
+ char *path = "/data/voip_playback.wav";
+ struct stat st;
+ struct riff_wave_header riff_wave_header;
+ struct chunk_header chunk_header;
+ struct chunk_fmt chunk_fmt = {0};
+ unsigned int more_chunks = 1;
+ uint32 header[4];
+
+ if(send_fd < 0) {
+ printf("Client socket not open.");
+ return;
+ }
+
+ /* Check and open source file */
+ if (access(path, F_OK) || stat(path, &st)) {
+ printf("%s: error reading from file %s\n", __FUNCTION__, path);
+ return;
+ }
+
+ if (!st.st_size) {
+ printf("%s: empty file %s\n", __FUNCTION__, path);
+ return;
+ }
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ printf("%s: error opening file %s\n", __FUNCTION__, path);
+ return;
+ }
+
+ lseek(fd, sizeof(struct wav_header), SEEK_SET);
+ uint32 sequence = 1;
+ uint32 timestamp = 0;
+ while (running) {
+ /* Playback loop */
+ memset(buf, 0x00, sizeof(buf));
+ len = read(fd, buf + 16, pack_size);
+ if (len == -1) {
+ printf("%s: error reading from file\n", __FUNCTION__);
+ break;
+ }
+
+ if (len == 0) {
+ /* reached EOF */
+ printf("%s: nothing to read\n", __FUNCTION__);
+ break;
+ }
+
+
+ header[0] = htonl(((uint32_t) 2 << 30) | ((uint32_t) 1 << 24) | ((uint32_t) 0x60 << 16) | ((uint32_t) sequence));
+ header[1] = htonl(timestamp);
+ header[2] = htonl(0xFFFF0000);
+ header[3] = htonl(0xFFFF0000);
+ memcpy(buf, &header, sizeof(header));
+
+ if((rc = sendto(send_fd, buf, len + 16, 0, NULL, 0)) < len + 16) {
+ printf("Send data fail: %d/%d\n", rc, len);
+ break;
+ } else {
+ printf("SEND : %d / %d\n", rc, len);
+ }
+
+ sequence++;
+ timestamp += len / 2;
+
+ ++frames;
+ //printf("%s: No.%d frame playback[len - %d]\n", __FUNCTION__, ++frames, len);
+ usleep(21000);
+ }
+
+ printf("playback_thread exit.\n");
+}
+
+static void sig_handler(int sig)
+{
+ running = FALSE;
+
+ printf("Success exit by signal...\n");
+
+ sleep(1);
+
+ exit(0);
+}
+
+static int rtp_udp_ser_open(const char *local_addr, int local_port)
+{
+ // No set local addr.
+ UNUSED(local_addr);
+
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(fd < 0){
+ printf("socket() fail.[%d]\n", errno);
+ return -1;
+ }
+
+ struct sockaddr_in servaddr;
+ memset(&servaddr, 0, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_port = htons(local_port);
+ servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ if (bind(fd, (struct sockaddr *)&servaddr, sizeof(struct sockaddr_in)) < 0) {
+ printf("bind() failed: %d\n", errno);
+ goto result_fail_with_close;
+ }
+
+ return fd;
+result_fail_with_close:
+ close(fd);
+ fd = -1;
+ printf("mbtk_sock_open() end:fail\n");
+ return -1;
+}
+
+static int rtp_udp_cli_open(const char *remote_addr, int remote_port)
+{
+ struct sockaddr_in dst_sa4, src_sa4;
+ if (inet_pton(AF_INET, "0.0.0.0", &src_sa4.sin_addr) > 0) {
+ src_sa4.sin_family = AF_INET;
+ src_sa4.sin_port = htons(0);
+ memset(&src_sa4.sin_zero, 0, sizeof(src_sa4.sin_zero));
+ } else {
+ printf("Set src addr fail.\n");
+ return -1;
+ }
+
+ if (inet_pton(AF_INET, remote_addr, &dst_sa4.sin_addr) > 0) {
+ dst_sa4.sin_family = AF_INET;
+ dst_sa4.sin_port = htons(remote_port);
+ memset(&dst_sa4.sin_zero, 0, sizeof(dst_sa4.sin_zero));
+ } else {
+ printf("Set dst addr fail.\n");
+ return -1;
+ }
+
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(fd < 0){
+ printf("socket() fail.[%d]\n", errno);
+ return -1;
+ }
+
+ if (bind(fd, (struct sockaddr*) &src_sa4, sizeof(src_sa4)) < 0) {
+ printf("bind() failed: %d\n", errno);
+ goto result_fail_with_close;
+ }
+
+ if (connect(fd, (struct sockaddr*) &dst_sa4, sizeof(dst_sa4)) < 0) {
+ printf("connect() failed: %d\n", errno);
+ goto result_fail_with_close;
+ }
+
+#if 0
+ if(socket_noblock(fd)) {
+ goto result_fail_with_close;
+ }
+#endif
+
+ return fd;
+result_fail_with_close:
+ close(fd);
+ fd = -1;
+ printf("mbtk_sock_open() end:fail\n");
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2) {
+ printf("mbtk_rtp_udp_cli <IP>\n");
+ return -1;
+ }
+
+ // mbtk_log_init("radio", "RTP_TEST");
+
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+
+
+ int ser_fd = rtp_udp_ser_open(NULL, RTP_UDP_SER_PORT_DEFAULT);
+ if(ser_fd < 0) {
+ printf("rtp_udp_ser_open() fail.\n");
+ return -1;
+ }
+
+ send_fd = rtp_udp_cli_open(argv[1], RTP_UDP_CLI_PORT_DEFAULT);
+ if(send_fd < 0) {
+ printf("rtp_udp_cli_open() fail.\n");
+ // return -1;
+ }
+
+ struct wav_header header;
+ int rc = 0;
+ char *path = "/data/voip_record.wav";
+
+ header.riff_id = ID_RIFF;
+ header.riff_sz = 0;
+ header.riff_fmt = ID_WAVE;
+ header.fmt_id = ID_FMT;
+ header.fmt_sz = 16;
+ header.audio_format = 1; //FORMAT_PCM;
+ header.num_channels = 1; //Modem ONLY support mono recording
+ header.sample_rate = 8000;
+ header.bits_per_sample = 16; //PCM_SAMPLEBITS_S16_LE;
+ header.byte_rate = (header.bits_per_sample / 8) * header.num_channels * header.sample_rate;
+ header.block_align = header.num_channels * (header.bits_per_sample / 8);
+ header.data_id = ID_DATA;
+
+ record_fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (record_fd < 0) {
+ printf("%s: error opening file %s!\n", __FUNCTION__, path);
+ return -1;
+ }
+
+ lseek(record_fd, 0, SEEK_SET);
+ write(record_fd, &header, sizeof(struct wav_header));
+
+ //leave enough room for header
+ lseek(record_fd, sizeof(struct wav_header), SEEK_SET);
+
+ char buff[2048];
+ int len_recv;
+ int len_send;
+ running = TRUE;
+ bool is_first = TRUE;
+ while(running) {
+ len_recv = recvfrom(ser_fd, buff, sizeof(buff), 0, NULL, NULL);
+ if(len_recv < 0) {
+ printf("recvfrom() ret is %d,errno - %d\n", len_recv, errno);
+ continue;
+ } else if(len_recv == 0) {
+ printf("ret is 0\n");
+ } else if(len_recv > 16){
+ printf("RECV:len - %d\n", len_recv);
+ write(record_fd, buff + 16, len_recv - 16);
+
+ if(is_first) {
+ pthread_t playabck_thread/*, record_thread*/;
+ rc = pthread_create(&playabck_thread, NULL, (void *)&voip_playback_run, NULL);
+ if (rc < 0) {
+ printf("error creating thread_start!");
+ break;
+ }
+ is_first = FALSE;
+ }
+
+#if 0
+ if(cli_fd < 0) {
+ cli_fd = rtp_udp_cli_open(argv[1], RTP_UDP_CLI_PORT_DEFAULT);
+ if(cli_fd < 0) {
+ printf("rtp_udp_cli_open() fail.\n");
+ // return -1;
+ } else {
+ printf("rtp_udp_cli_open() success.\n");
+ }
+ }
+
+ if(cli_fd > 0) {
+ len_send = sendto(cli_fd, buff, len_recv, 0, NULL, 0);
+ printf("SEND : %d / %d\n", len_send, len_recv);
+ }
+#endif
+ } else {
+ printf("RTP Header error.\n");
+ }
+ }
+
+ close(record_fd);
+
+ close(ser_fd);
+
+ return 0;
+}
+
+
diff --git a/mbtk/test/others/mbtk_spi_write.c b/mbtk/test/others/mbtk_spi_write.c
new file mode 100755
index 0000000..be15742
--- /dev/null
+++ b/mbtk/test/others/mbtk_spi_write.c
@@ -0,0 +1,320 @@
+#include <stdint.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/types.h>
+#include <linux/spi/spidev.h>
+
+#define SPI_DEBUG 1
+#define DEBUG_SWITCH 1 /* 打开调试信息打印功能 */
+#define ERR_DEBUG_SWITCH 1 /* 打印错误信息打印功能 */
+
+/**
+* 简单打印调试信息
+*/
+#if DEBUG_SWITCH
+#define pr_debug(fmt,args...) printf(fmt, ##args)
+#else
+#define pr_debug(fmt,args...) /*do nothing */
+#endif
+
+/**
+* 错误信息打印
+* 自动打印发生错误时代码所在的位置
+*/
+#if ERR_DEBUG_SWITCH
+#define pr_err(fmt,args...) printf("\nError:\nFile:<%s> Fun:[%s] Line:%d\n "fmt, __FILE__, __FUNCTION__, __LINE__, ##args)
+#else
+#define pr_err(fmt,args...) /*do nothing */
+#endif
+
+
+/*
+* 说明:SPI通讯实现
+* 方式一: 同时发送与接收实现函数: SPI_Transfer()
+* 方式二:发送与接收分开来实现
+* SPI_Write() 只发送
+* SPI_Read() 只接收
+* 两种方式不同之处:方式一,在发的过程中也在接收,第二种方式,收与发单独进行
+* Created on: 2013-5-28
+* Author: lzy
+*/
+static char device[64] = {0};
+static uint8_t mode = 0; /* SPI通信使用全双工,设置CPOL=0,CPHA=0。 */
+static uint8_t bits = 8; /* 8bits读写,MSB first。*/
+static uint32_t speed = 12 * 1000 * 1000;/* 设置12M传输速度 */
+static uint16_t delay = 0;
+static int g_SPI_Fd = 0;
+
+static void pabort(const char *s)
+{
+ perror(s);
+ abort();
+}
+
+/**
+* 功 能:同步数据传输
+* 入口参数 :
+* TxBuf -> 发送数据首地址
+* len -> 交换数据的长度
+* 出口参数:
+* RxBuf -> 接收数据缓冲区
+* 返回值:0 成功
+* 开发人员:Lzy 2013-5-22
+*/
+int SPI_Transfer(const uint8_t *TxBuf, uint8_t *RxBuf, int len)
+{
+ int ret;
+ int fd = g_SPI_Fd;
+
+ struct spi_ioc_transfer tr = {
+ .tx_buf = (unsigned long) TxBuf,
+ .rx_buf = (unsigned long) RxBuf,
+ .len = len,
+ .delay_usecs = delay,
+ };
+
+ ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
+ if (ret < 1)
+ pr_err("can't send spi message");
+ else
+ {
+#if SPI_DEBUG
+ int i;
+ pr_debug("\nmbtk: send spi message Succeed");
+ pr_debug("\nmbtk: SPI Send [Len:%d]: ", len);
+ for (i = 0; i < len; i++)
+ {
+ if (i % 8 == 0)
+ printf("\n\t");
+ printf("0x%02X ", TxBuf[i]);
+ }
+ printf("\n");
+
+ pr_debug("mbtk: SPI Receive [len:%d]:", len);
+ for (i = 0; i < len; i++)
+ {
+ if (i % 8 == 0)
+ printf("\n\t");
+ printf("0x%02X ", RxBuf[i]);
+ }
+ printf("\n");
+#endif
+ }
+ return ret;
+}
+
+/**
+* 功 能:发送数据
+* 入口参数 :
+* TxBuf -> 发送数据首地址
+* len -> 发送与长度
+*返回值:0 成功
+* 开发人员:Lzy 2013-5-22
+*/
+int SPI_Write(uint8_t *TxBuf, int len)
+{
+ int ret;
+ int fd = g_SPI_Fd;
+
+ ret = write(fd, TxBuf, len);
+ if (ret < 0)
+ pr_err("SPI Write error\n");
+ else
+ {
+#if SPI_DEBUG
+ int i;
+ pr_debug("\nSPI Write [Len:%d]: ", len);
+ for (i = 0; i < len; i++)
+ {
+ if (i % 8 == 0)
+ printf("\n\t");
+ printf("0x%02X ", TxBuf[i]);
+ }
+ printf("\n");
+
+#endif
+ }
+
+ return ret;
+}
+
+/**
+* 功 能:接收数据
+* 出口参数:
+* RxBuf -> 接收数据缓冲区
+* rtn -> 接收到的长度
+* 返回值:>=0 成功
+* 开发人员:Lzy 2013-5-22
+*/
+int SPI_Read(uint8_t *RxBuf, int len)
+{
+ int ret;
+ int fd = g_SPI_Fd;
+ ret = read(fd, RxBuf, len);
+ if (ret < 0)
+ pr_err("SPI Read error\n");
+ else
+ {
+#if SPI_DEBUG
+ int i;
+ pr_debug("SPI Read [len:%d]:", len);
+ for (i = 0; i < len; i++)
+ {
+ if (i % 8 == 0)
+ printf("\n\t");
+ printf("0x%02X ", RxBuf[i]);
+ }
+ printf("\n");
+#endif
+ }
+
+ return ret;
+}
+
+/**
+* 功 能:打开设备 并初始化设备
+* 入口参数 :
+* 出口参数:
+* 返回值:0 表示已打开 0XF1 表示SPI已打开 其它出错
+* 开发人员:Lzy 2013-5-22
+*/
+int SPI_Open(void)
+{
+ int fd;
+ int ret = 0;
+
+ if (g_SPI_Fd != 0) /* 设备已打开 */
+ return 0xF1;
+
+ fd = open(device, O_RDWR);
+ if (fd < 0)
+ pabort("can't open device");
+ else
+ pr_debug("SPI - Open Succeed. Start Init SPI...\n");
+
+ g_SPI_Fd = fd;
+ /*
+ * spi mode
+ */
+ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
+ if (ret == -1)
+ pabort("can't set spi mode");
+
+ ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
+ if (ret == -1)
+ pabort("can't get spi mode");
+
+ /*
+ * bits per word
+ */
+ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
+ if (ret == -1)
+ pabort("can't set bits per word");
+
+ ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
+ if (ret == -1)
+ pabort("can't get bits per word");
+
+ /*
+ * max speed hz
+ */
+ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
+ if (ret == -1)
+ pabort("can't set max speed hz");
+
+ ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
+ if (ret == -1)
+ pabort("can't get max speed hz");
+
+ pr_debug("spi mode: %d\n", mode);
+ pr_debug("bits per word: %d\n", bits);
+ pr_debug("max speed: %d KHz (%d MHz)\n", speed / 1000, speed / 1000 / 1000);
+
+ return ret;
+}
+
+/**
+* 功 能:关闭SPI模块
+*/
+int SPI_Close(void)
+{
+ int fd = g_SPI_Fd;
+
+ if (fd == 0) /* SPI是否已经打开*/
+ return 0;
+ close(fd);
+ g_SPI_Fd = 0;
+
+ return 0;
+}
+
+/**
+* 功 能:自发自收测试程序
+* 接收到的数据与发送的数据如果不一样 ,则失败
+* 说明:
+* 在硬件上需要把输入与输出引脚短跑
+* 开发人员:Lzy 2013-5-22
+*/
+int SPI_LookBackTest(void)
+{
+ int ret, i;
+ const int BufSize = 16;
+ uint8_t tx[BufSize], rx[BufSize];
+
+ bzero(rx, sizeof(rx));
+ for (i = 0; i < BufSize; i++)
+ tx[i] = i;
+
+ pr_debug("\nSPI - LookBack Mode Test...\n");
+ ret = SPI_Transfer(tx, rx, BufSize);
+ if (ret > 1)
+ {
+ ret = memcmp(tx, rx, BufSize);
+ if (ret != 0)
+ {
+ pr_err("LookBack Mode Test error\n");
+// pabort("error");
+ }
+ else
+ pr_debug("SPI - LookBack Mode OK\n");
+ }
+
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret = 0;
+
+ if(argc == 2)
+ {
+ memset(device, 0x0, 64);
+ memcpy(device, argv[1], strlen(argv[1]));
+ printf("device: %s\n", device);
+ }
+ else
+ {
+ printf("format: mbtk_spi_write <dev>\n");
+ return -1;
+ }
+ ret = SPI_Open();
+ if (ret)
+ return ret;
+
+ SPI_LookBackTest();
+
+// unsigned char buf[10];
+// SPI_Write(buf, 10);
+// SPI_Read(buf, 10);
+
+ SPI_Close();
+
+return 0;
+}
+
diff --git a/mbtk/test/others/partition_write_demo.c b/mbtk/test/others/partition_write_demo.c
new file mode 100755
index 0000000..5edfa2d
--- /dev/null
+++ b/mbtk/test/others/partition_write_demo.c
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
+{
+
+#if 1
+ // 100K
+ char buffer[102400];
+ long len = -1;
+ long count = 0;
+ int fd = open("/etc/file.temp", O_CREAT | O_WRONLY | O_TRUNC, 0666);
+ if(fd < 0) {
+ printf("Open file error:%d\n", errno);
+ return -1;
+ }
+
+ while((len = write(fd, buffer, sizeof(buffer))) > 0){
+ count += len;
+ printf("write : %ld\n", count);
+ //usleep(1000);
+ }
+
+ printf("Write complete,len = %ld, errno = %d\n", len, errno);
+
+ close(fd);
+#else
+ // 100K
+ int buffer = 1;
+ long len = -1;
+ long count = 0;
+
+ FILE *file = fopen("/etc/file.temp", "w");
+ if(file == NULL) {
+ printf("Open file error:%d\n", errno);
+ return -1;
+ }
+
+ while((len = fwrite(&buffer, sizeof(int), 1,file)) > 0){
+ buffer++;
+
+ // printf("write : %d\n", buffer);
+ //usleep(1000);
+ }
+
+ printf("Write complete,len = %d, errno = %d\n", len, errno);
+
+ fclose(file);
+#endif
+ return 0;
+}
+
diff --git a/mbtk/test/others/polarssl_demo.c b/mbtk/test/others/polarssl_demo.c
new file mode 100755
index 0000000..1405fdb
--- /dev/null
+++ b/mbtk/test/others/polarssl_demo.c
@@ -0,0 +1,488 @@
+#include <stdio.h>
+
+#ifdef MBTK_POLARSSL_SUPPORT
+#include "mbtk_log.h"
+#include "ql/ql_mcm_sim.h"
+#include <sys/socket.h>
+#include <polarssl/net.h>
+#include <polarssl/ssl.h>
+#include <polarssl/entropy.h>
+#include <polarssl/ctr_drbg.h>
+#include <polarssl/certs.h>
+#include <polarssl/x509.h>
+#include <polarssl/error.h>
+#include <polarssl/debug.h>
+#include <polarssl/config.h>
+
+#define DFL_SERVER_NAME "asr"
+#define DFL_SERVER_ADDR NULL
+#define DFL_SERVER_PORT 4433
+#define DFL_REQUEST_PAGE "/"
+#define DFL_REQUEST_SIZE -1
+#define DFL_DEBUG_LEVEL 0
+#define DFL_NBIO 0
+#define DFL_CA_FILE "/ca.crt"
+#define DFL_CA_PATH "/ca.crt"
+#define DFL_CRT_FILE "/client.crt"
+#define DFL_KEY_FILE "/client.key"
+#define DFL_PSK ""
+#define DFL_PSK_IDENTITY "Client_identity"
+#define DFL_FORCE_CIPHER 0
+#define DFL_RENEGOTIATION SSL_RENEGOTIATION_DISABLED
+#define DFL_ALLOW_LEGACY SSL_LEGACY_NO_RENEGOTIATION
+#define DFL_RENEGOTIATE 0
+#define DFL_EXCHANGES 1
+#define DFL_MIN_VERSION SSL_MINOR_VERSION_3
+#define DFL_MAX_VERSION SSL_MINOR_VERSION_3
+#define DFL_AUTH_MODE SSL_VERIFY_REQUIRED
+#define DFL_MFL_CODE SSL_MAX_FRAG_LEN_NONE
+#define DFL_TRUNC_HMAC 0
+#define DFL_RECONNECT 0
+#define DFL_RECO_DELAY 0
+#define DFL_TICKETS SSL_SESSION_TICKETS_ENABLED
+#define DFL_ALPN_STRING NULL
+
+#define GET_REQUEST "GET %s HTTP/1.0\r\nExtra-header: "
+#define GET_REQUEST_END "\r\n\r\n"
+
+#define CA_CERT \
+"-----BEGIN CERTIFICATE-----\r\n" \
+"MIIDKjCCAhICCQCOewfZiRCiNjANBgkqhkiG9w0BAQUFADBXMQswCQYDVQQGEwJD\r\n" \
+"TjEQMA4GA1UECBMHU2lDaHVhbjEVMBMGA1UEChMMTU9CSUxFVEVLLkNBMQswCQYD\r\n" \
+"VQQLEwJJVDESMBAGA1UEAxMJTU9CSUxFVEVLMB4XDTE4MDkxODA4MDUzMloXDTMz\r\n" \
+"MDkxOTA4MDUzMlowVzELMAkGA1UEBhMCQ04xEDAOBgNVBAgTB1NpQ2h1YW4xFTAT\r\n" \
+"BgNVBAoTDE1PQklMRVRFSy5DQTELMAkGA1UECxMCSVQxEjAQBgNVBAMTCU1PQklM\r\n" \
+"RVRFSzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOkdYJF1h1xjKbY0\r\n" \
+"ipbl88G653PiCh8ZMjmIUYeiDKC8+0wtXZtHvQIl6AncOzBy9XHVOctbKn34exC8\r\n" \
+"SEotMuo2T49vs9VtE8GYu2pOrf3m42NpLRnYAxfm9qw53CMHx+Jn7Oa9fnxa8haA\r\n" \
+"pRc2BTVadWGoS8EEwoZFk0eNb7Z2Gc7U0c+GhISI4oVTTocGvGgMzkvduu5JJbbc\r\n" \
+"BOcNFrii9sRO9vtOYQtqOEg01Uum2Dwp/o2bDLXNJEqAIh4WACiM4iPmmlRHWT2y\r\n" \
+"NjQ3vcbEdrFwbHRtO46+Vw54HnSyCoFb3uCHMNMvXObZ/8AU9E3Cgat4j0sgEeB0\r\n" \
+"hqA4MiMCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEAtEAjf0CjsLgG9ROdmp1qXYft\r\n" \
+"+ndIT5l82KRK57ZQsfdFbnJOvALeF/ICKU0M2TXgJNiGOA5RxDi00YYdMbOIPwVZ\r\n" \
+"JH4b87J/LYdLAGf+Q+kVI6gWH3hPm4Jzfzq/40KVrf3mpa54yWz6ZYtwfxBjrMgr\r\n" \
+"IVe0O5SIJ99lsddgzgUkqYN2vWJW2zZ50xuXOAyo+pOnjzX0wuOcaBT3JCHWJRAb\r\n" \
+"VhJCf9JbswDgnddJerqFtB8pnpAOdGokLCOoM06q3s3P9mhGX+72HXdX7G8CSAuG\r\n" \
+"PVCGf6RaF0/G4B9R1c3du3lZRlQWfx2pxyU0LS86iFQFWqzqcWEXIcULVdcErQ==\r\n" \
+"-----END CERTIFICATE-----\r\n"
+
+const char ca1_cert[]= CA_CERT;
+
+
+struct options
+{
+ const char *server_name; /* hostname of the server (client only) */
+ const char *server_addr; /* address of the server (client only) */
+ int server_port; /* port on which the ssl service runs */
+ int debug_level; /* level of debugging */
+ int nbio; /* should I/O be blocking? */
+ const char *request_page; /* page on server to request */
+ int request_size; /* pad request with header to requested size */
+ const char *ca_file; /* the file with the CA certificate(s) */
+ const char *ca_path; /* the path with the CA certificate(s) reside */
+ const char *crt_file; /* the file with the client certificate */
+ const char *key_file; /* the file with the client key */
+ const char *psk; /* the pre-shared key */
+ const char *psk_identity; /* the pre-shared key identity */
+ int force_ciphersuite[2]; /* protocol/ciphersuite to use, or all */
+ int renegotiation; /* enable / disable renegotiation */
+ int allow_legacy; /* allow legacy renegotiation */
+ int renegotiate; /* attempt renegotiation? */
+ int renego_delay; /* delay before enforcing renegotiation */
+ int exchanges; /* number of data exchanges */
+ int min_version; /* minimum protocol version accepted */
+ int max_version; /* maximum protocol version accepted */
+ int auth_mode; /* verify mode for connection */
+ unsigned char mfl_code; /* code for maximum fragment length */
+ int trunc_hmac; /* negotiate truncated hmac or not */
+ int reconnect; /* attempt to resume session */
+ int reco_delay; /* delay in seconds before resuming session */
+ int tickets; /* enable / disable session tickets */
+ const char *alpn_string; /* ALPN supported protocols */
+} opt;
+
+
+static sim_client_handle_type cli_handle;
+int server_fd = -1;
+
+static void my_debug( void *ctx, int level, const char *str )
+{
+ ((void) level);
+
+ fprintf( (FILE *) ctx, "%s", str );
+ fflush( (FILE *) ctx );
+}
+
+
+static int ssl_client_init()
+{
+ int ret = 0, len, tail_len, i, written, frags;
+ unsigned char buf[SSL_MAX_CONTENT_LEN + 1];
+ const char *pers = "ssl_client";
+
+ entropy_context entropy;
+ ctr_drbg_context ctr_drbg;
+ ssl_context ssl;
+ ssl_session saved_session;
+ x509_crt cacert;
+ x509_crt clicert;
+ pk_context pkey;
+
+ memset( &ssl, 0, sizeof( ssl_context ) );
+ memset( &saved_session, 0, sizeof( ssl_session ) );
+ x509_crt_init( &cacert );
+ x509_crt_init( &clicert );
+ pk_init( &pkey );
+
+ fflush( stdout );
+
+ /*
+ * 0. Initialize the RNG and the session data
+ */
+
+ entropy_init( &entropy );
+ if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
+ (const unsigned char *) pers,
+ strlen( pers ) ) ) != 0 )
+ {
+ printf( " failed\n ! ctr_drbg_init returned -0x%x\n", -ret );
+ goto exit;
+ }
+
+ printf( " ok\n" );
+
+ /*
+ * 1.1. Load the trusted CA
+ */
+ //ret = x509_crt_parse(&cacert,ca1_cert,strlen(ca1_cert));
+ ret = x509_crt_parse_file( &cacert, opt.ca_path );
+ if( ret < 0 )
+ {
+ printf( " failed\n ! ca x509_crt_parse returned -0x%x\n\n", -ret );
+ goto exit;
+ }
+ printf( " ok\n" );
+
+ /*
+ * 1.2. Load own certificate and private key
+ *
+ * (can be skipped if client authentication is not required)
+ */
+
+ ret = x509_crt_parse_file( &clicert, opt.crt_file );
+ if( ret != 0 )
+ {
+ printf( " failed\n ! crt x509_crt_parse returned -0x%x\n\n", -ret );
+ goto exit;
+ }
+
+ ret = pk_parse_keyfile( &pkey, opt.key_file, NULL);
+ if( ret != 0 )
+ {
+ printf( " failed\n ! key x509_crt_parse returned -0x%x\n\n", -ret );
+ goto exit;
+ }
+
+ printf( " ok\n" );
+
+ /*
+ * 2. Setup stuff
+ */
+ printf( " . Setting up the SSL/TLS structure..." );
+ fflush( stdout );
+
+ if( ( ret = ssl_init( &ssl ) ) != 0 )
+ {
+ printf( " failed\n ! ssl_init returned -0x%x\n\n", -ret );
+ goto exit;
+ }
+
+ ssl_set_endpoint( &ssl, SSL_IS_CLIENT );
+ ssl_set_authmode( &ssl, opt.auth_mode );
+
+ ssl_set_rng( &ssl, ctr_drbg_random, &ctr_drbg );
+ ssl_set_dbg( &ssl, my_debug, stdout );
+
+ ssl_set_bio( &ssl, net_recv, &server_fd, net_send, &server_fd );
+
+ ssl_set_renegotiation( &ssl, opt.renegotiation );
+ ssl_legacy_renegotiation( &ssl, opt.allow_legacy );
+
+ ssl_set_ca_chain( &ssl, &cacert, NULL, NULL );
+
+ if( ( ret = ssl_set_own_cert( &ssl, &clicert, &pkey ) ) != 0 )
+ {
+ printf( " failed\n ! ssl_set_own_cert returned %d\n\n", ret );
+ goto exit;
+ }
+ if( opt.min_version != -1 )
+ ssl_set_min_version( &ssl, SSL_MAJOR_VERSION_3, opt.min_version );
+ if( opt.max_version != -1 )
+ ssl_set_max_version( &ssl, SSL_MAJOR_VERSION_3, opt.max_version );
+ printf( " ok\n" );
+ /*
+ * 3. Handshake
+ */
+ printf( " . Performing the SSL/TLS handshake..." );
+ fflush( stdout );
+
+ while( ( ret = ssl_handshake( &ssl ) ) != 0 )
+ {
+ if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
+ {
+ printf( " failed\n ! ssl_handshake returned -0x%x\n", -ret );
+ if( ret == POLARSSL_ERR_X509_CERT_VERIFY_FAILED )
+ printf(
+ " Unable to verify the server's certificate. "
+ "Either it is invalid,\n"
+ " or you didn't set ca_file or ca_path "
+ "to an appropriate value.\n"
+ " Alternatively, you may want to use "
+ "auth_mode=optional for testing purposes.\n" );
+ printf( "\n" );
+ goto exit;
+ }
+ }
+
+ printf( " ok\n [ Protocol is %s ]\n [ Ciphersuite is %s ]\n",
+ ssl_get_version( &ssl ), ssl_get_ciphersuite( &ssl ) );
+
+ /*
+ * 4. Verify the server certificate
+ */
+ printf( " . Verifying peer X.509 certificate..." );
+
+ if( ( ret = ssl_get_verify_result( &ssl ) ) != 0 )
+ {
+ printf( " failed\n" );
+
+ if( ( ret & BADCERT_EXPIRED ) != 0 )
+ printf( " ! server certificate has expired\n" );
+
+ if( ( ret & BADCERT_REVOKED ) != 0 )
+ printf( " ! server certificate has been revoked\n" );
+
+ if( ( ret & BADCERT_CN_MISMATCH ) != 0 )
+ printf( " ! CN mismatch (expected CN=%s)\n", opt.server_name );
+
+ if( ( ret & BADCERT_NOT_TRUSTED ) != 0 )
+ printf( " ! self-signed or not signed by a trusted CA\n" );
+
+ printf( "\n" );
+ }
+ else
+ printf( " ok\n" );
+
+ if( ssl_get_peer_cert( &ssl ) != NULL )
+ {
+ printf( " . Peer certificate information ...\n" );
+ x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
+ ssl_get_peer_cert( &ssl ) );
+ printf( "%s\n", buf );
+ }
+ /*
+ * 5. Write the GET request
+ */
+ printf( " > Write to server:" );
+ fflush( stdout );
+
+ len = snprintf( (char *) buf, sizeof(buf) - 1, GET_REQUEST,
+ opt.request_page );
+ tail_len = strlen( GET_REQUEST_END );
+
+ /* Add padding to GET request to reach opt.request_size in length */
+ if( opt.request_size != DFL_REQUEST_SIZE &&
+ len + tail_len < opt.request_size )
+ {
+ memset( buf + len, 'A', opt.request_size - len - tail_len );
+ len += opt.request_size - len - tail_len;
+ }
+
+ strncpy( (char *) buf + len, GET_REQUEST_END, sizeof(buf) - len - 1 );
+ len += tail_len;
+
+ /* Truncate if request size is smaller than the "natural" size */
+ if( opt.request_size != DFL_REQUEST_SIZE &&
+ len > opt.request_size )
+ {
+ len = opt.request_size;
+
+ /* Still end with \r\n unless that's really not possible */
+ if( len >= 2 ) buf[len - 2] = '\r';
+ if( len >= 1 ) buf[len - 1] = '\n';
+ }
+
+ for( written = 0, frags = 0; written < len; written += ret, frags++ )
+ {
+ while( ( ret = ssl_write( &ssl, buf + written, len - written ) ) <= 0 )
+ {
+ if( ret != POLARSSL_ERR_NET_WANT_READ && ret != POLARSSL_ERR_NET_WANT_WRITE )
+ {
+ printf( " failed\n ! ssl_write returned -0x%x\n\n", -ret );
+ goto exit;
+ }
+ }
+ }
+
+ buf[written] = '\0';
+ printf( " %d bytes written in %d fragments\n\n%s\n", written, frags, (char *) buf );
+
+ /*
+ * 6. Read the HTTP response
+ */
+ printf( " < Read from server:" );
+ fflush( stdout );
+
+ do
+ {
+ len = sizeof( buf ) - 1;
+ memset( buf, 0, sizeof( buf ) );
+ ret = ssl_read( &ssl, buf, len );
+
+ if( ret == POLARSSL_ERR_NET_WANT_READ ||
+ ret == POLARSSL_ERR_NET_WANT_WRITE )
+ continue;
+
+ if( ret <= 0 )
+ {
+ switch( ret )
+ {
+ case POLARSSL_ERR_SSL_PEER_CLOSE_NOTIFY:
+ printf( " connection was closed gracefully\n" );
+ ret = 0;
+ goto close_notify;
+
+ case 0:
+ case POLARSSL_ERR_NET_CONN_RESET:
+ printf( " connection was reset by peer\n" );
+ ret = 0;
+ goto exit;
+
+ default:
+ printf( " ssl_read returned -0x%x\n", -ret );
+ goto exit;
+ }
+ }
+
+ len = ret;
+ buf[len] = '\0';
+ printf( " %d bytes read\n\n%s", len, (char *) buf );
+
+ /* End of message should be detected according to the syntax of the
+ * application protocol (eg HTTP), just use a dummy test here. */
+ if( ret > 0 && buf[len-1] == '\n' )
+ {
+ ret = 0;
+ break;
+ }
+ }
+ while( 1 );
+
+ /*
+ * 7. Done, cleanly close the connection
+ */
+close_notify:
+ printf( " . Closing the connection..." );
+
+ while( ( ret = ssl_close_notify( &ssl ) ) < 0 )
+ {
+ if( ret == POLARSSL_ERR_NET_CONN_RESET )
+ {
+ printf( " ok (already closed by peer)\n" );
+ ret = 0;
+ goto exit;
+ }
+
+ if( ret != POLARSSL_ERR_NET_WANT_READ &&
+ ret != POLARSSL_ERR_NET_WANT_WRITE )
+ {
+ printf( " failed\n ! ssl_close_notify returned %d\n\n", ret );
+ goto exit;
+ }
+ }
+
+ printf( " ok\n" );
+exit:
+ if( server_fd )
+ net_close( server_fd );
+
+ x509_crt_free( &clicert );
+ x509_crt_free( &cacert );
+ pk_free( &pkey );
+ ssl_session_free( &saved_session );
+ ssl_free( &ssl );
+ ctr_drbg_free( &ctr_drbg );
+ entropy_free( &entropy );
+
+ printf( " ok end\n" );
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ printf("Start!\n");
+
+ opt.server_name = DFL_SERVER_NAME;
+ opt.server_addr = DFL_SERVER_ADDR;
+ opt.server_port = DFL_SERVER_PORT;
+ opt.debug_level = DFL_DEBUG_LEVEL;
+ opt.nbio = DFL_NBIO;
+ opt.request_page = DFL_REQUEST_PAGE;
+ opt.request_size = DFL_REQUEST_SIZE;
+ opt.ca_file = DFL_CA_FILE;
+ opt.ca_path = DFL_CA_PATH;
+ opt.crt_file = DFL_CRT_FILE;
+ opt.key_file = DFL_KEY_FILE;
+ opt.psk = DFL_PSK;
+ opt.psk_identity = DFL_PSK_IDENTITY;
+ opt.force_ciphersuite[0]= DFL_FORCE_CIPHER;
+ opt.renegotiation = DFL_RENEGOTIATION;
+ opt.allow_legacy = DFL_ALLOW_LEGACY;
+ opt.renegotiate = DFL_RENEGOTIATE;
+ opt.exchanges = DFL_EXCHANGES;
+ opt.min_version = DFL_MIN_VERSION;
+ opt.max_version = DFL_MAX_VERSION;
+ opt.auth_mode = DFL_AUTH_MODE;
+ opt.mfl_code = DFL_MFL_CODE;
+ opt.trunc_hmac = DFL_TRUNC_HMAC;
+ opt.reconnect = DFL_RECONNECT;
+ opt.reco_delay = DFL_RECO_DELAY;
+ opt.tickets = DFL_TICKETS;
+ opt.alpn_string = DFL_ALPN_STRING;
+
+
+ if(argc < 3)
+ {
+ printf("input error \n example: mbtk_test ip prot\n");
+ return -1;
+ }
+ opt.server_addr = argv[1];
+ opt.server_port = atoi(argv[2]);
+
+ int ret = -1;
+ if( ( ret = net_connect( &server_fd, opt.server_addr,
+ opt.server_port ) ) != 0 )
+ {
+ printf( " failed\n ! net_connect returned -0x%x\n\n", -ret );
+ return -1;
+ }
+
+ ret = net_set_nonblock( server_fd );
+ if( ret != 0 )
+ {
+ printf( " failed\n ! net_set_(non)block() returned -0x%x\n\n", -ret );
+ return -1;
+ }
+ printf( " ok\n" );
+ ret = ssl_client_init();
+ printf("ret is %d\n",ret);
+ printf("End!\n");
+ return 0;
+}
+#else
+int main(int argc, char *argv[])
+{
+ printf("No support polarssl.\n");
+ return 0;
+}
+#endif
\ No newline at end of file
diff --git a/mbtk/test/others/proc_demo.c b/mbtk/test/others/proc_demo.c
new file mode 100755
index 0000000..929984c
--- /dev/null
+++ b/mbtk/test/others/proc_demo.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int pub_int_d = 4;
+char *str = "abc";
+int bss_1;
+
+//int bss_1;
+//static int static_bss_2;
+
+void test(int c)
+{
+// int d = 10;
+ //printf("函数参数:test_c = %p, 局部变量:d = %p\n", &c, &d);
+}
+
+int main(int argc, char *argv[])
+{
+ printf("[栈]函数参数:argc = %p, argv = %p\n", &argc, argv);
+
+ int int_a;
+ static int static_int_b;
+ char *temp_malloc = (char*)malloc(10);
+ const char temp[10];
+
+ printf("[栈]局部变量:int_a[%d] = %p, [BSS]局部静态变量:static_int_b[%d] = %p\n", int_a, &int_a, static_int_b, &static_int_b);
+ printf("[DATA]全局变量:pub_int_d[%d] = %p\n", pub_int_d, &pub_int_d);
+ printf("常量:str = %p, 堆空间:temp_malloc = %p\n", str, temp_malloc);
+ printf("函数:test_func = %p\n", test);
+ printf("const_str = %p, &(temp[3]) = %p\n", temp, &(temp[3]));
+ printf("BSS : %d, %p\n", bss_1, &bss_1);
+
+ test(5);
+
+ while(1) {
+ sleep(24 * 60 * 60);
+ }
+
+ return 0;
+}
+
diff --git a/mbtk/test/others/touch_ev_demo.c b/mbtk/test/others/touch_ev_demo.c
new file mode 100755
index 0000000..133384b
--- /dev/null
+++ b/mbtk/test/others/touch_ev_demo.c
@@ -0,0 +1,376 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <linux/input.h>
+#include <unistd.h>
+#include <linux/fb.h>
+#include <sys/mman.h>
+#include <time.h>
+#include <pthread.h>
+#include <sys/poll.h>
+#include <dirent.h>
+#include <stdbool.h>
+
+// #include "mbtk_log.h"
+
+#ifndef TRUE
+#define TRUE 1 /* Boolean true value. */
+#endif
+
+#ifndef true
+#define true 1 /* Boolean true value. */
+#endif
+
+#ifndef FALSE
+#define FALSE 0 /* Boolean false value. */
+#endif
+
+#ifndef false
+#define false 0 /* Boolean false value. */
+#endif
+
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+
+#ifndef null
+#define null 0
+#endif
+
+#define LOGI printf
+#define LOGE printf
+
+/**
+ * Compiler-digit : 16
+ * char : 1 (%c)
+ * char* : 2
+ * short int : 2
+ * int : 2 (%d)
+ * unsigned int : 2 (%u)
+ * float : 4 (%f)
+ * double : 8 (%f)
+ * long : 4
+ * unsigned long : 4
+ * long long : 8
+ * unsigned long long : 8
+ *
+ *
+ * Compiler-digit : 32
+ * char : 1
+ * char* : 4
+ * short int : 2
+ * int : 4
+ * unsigned int : 4
+ * float : 4
+ * double : 8
+ * long : 4
+ * unsigned long : 4
+ * long long : 8
+ * unsigned long long : 8
+ *
+ *
+ * Compiler-digit : 64
+ * char : 1
+ * char* : 8
+ * short int : 2
+ * int : 4
+ * unsigned int : 4
+ * float : 4
+ * double : 8
+ * long : 8
+ * unsigned long : 8
+ * long long : 8
+ * unsigned long long : 8
+ */
+typedef unsigned char boolean; /* Boolean value type. */
+// typedef unsigned char bool; /* Boolean value type. */
+typedef unsigned long long uint64; /* Unsigned 64 bit value */
+typedef unsigned long long uint64_t; /* Unsigned 64 bit value */
+typedef unsigned int uint32; /* Unsigned 32 bit value */
+typedef unsigned int uint32_t; /* Unsigned 32 bit value */
+typedef unsigned short uint16; /* Unsigned 16 bit value */
+typedef unsigned short uint16_t;
+typedef unsigned char uint8; /* Unsigned 8 bit value */
+typedef unsigned char uint8_t;
+typedef signed long long int64; /* Signed 64 bit value */
+typedef signed long long sint64; /* Signed 64 bit value */
+typedef signed int int32; /* Signed 32 bit value */
+typedef signed int sint32; /* Signed 32 bit value */
+typedef signed short int16; /* Signed 16 bit value */
+typedef signed short sint16; /* Signed 16 bit value */
+typedef signed char int8; /* Signed 8 bit value */
+typedef signed char sint8; /* Signed 8 bit value */
+typedef unsigned char byte; /* byte type */
+
+//#include "mbtk_type.h"
+//#include "mbtk_log.h"
+
+typedef int (*ev_callback)(int fd, uint32_t epevents, void *data);
+
+typedef enum {
+ ACTION_DOWN,
+ ACTION_MOVE,
+ ACTION_UP,
+ ACTION_CANCEL
+} touch_event_action_enum;
+
+typedef struct {
+ touch_event_action_enum action;
+ int x;
+ int y;
+} touch_event;
+
+static int move_x;
+static touch_event event_pre;
+static bool action_down_get = false;
+static bool action_touched = false;
+
+#define MAX_DEVICES 16
+#define MAX_MISC_FDS 16
+
+#define BITS_PER_LONG (sizeof(unsigned long) * 8)
+#define BITS_TO_LONGS(x) (((x) + BITS_PER_LONG - 1) / BITS_PER_LONG)
+
+#define test_bit(bit, array) \
+ ((array)[(bit)/BITS_PER_LONG] & (1 << ((bit) % BITS_PER_LONG)))
+
+struct fd_info {
+ ev_callback cb;
+ void *data;
+};
+
+static struct pollfd ev_fds[MAX_DEVICES + MAX_MISC_FDS];
+static struct fd_info ev_fdinfo[MAX_DEVICES + MAX_MISC_FDS];
+
+static unsigned ev_count = 0;
+static unsigned ev_dev_count = 0;
+static unsigned ev_misc_count = 0;
+
+int ev_get_input(int fd, short revents, struct input_event *ev);
+bool event_process(struct input_event ev);
+
+int ev_cb(int fd, uint32_t epevents, void *data)
+{
+ struct input_event ev;
+
+ int retval = ev_get_input(fd, epevents, &ev);
+ if(retval < 0) return -1;
+
+ if(!event_process(ev)) return 0;
+
+ return 0;
+}
+
+int ev_init(void *data)
+{
+ DIR *dir;
+ struct dirent *de;
+ int fd;
+
+ dir = opendir("/dev/input");
+ if(dir != 0) {
+ while((de = readdir(dir))) {
+ unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)];
+
+// fprintf(stderr,"/dev/input/%s\n", de->d_name);
+ if(strncmp(de->d_name,"event",5)) continue;
+ fd = openat(dirfd(dir), de->d_name, O_RDONLY);
+ if(fd < 0) continue;
+
+ /* read the evbits of the input device */
+ if (ioctl(fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits) < 0) {
+ close(fd);
+ continue;
+ }
+
+ /* TODO: add ability to specify event masks. For now, just assume
+ * that only EV_KEY and EV_REL event types are ever needed. */
+ if (!test_bit(EV_KEY, ev_bits) && !test_bit(EV_REL, ev_bits)) {
+ close(fd);
+ continue;
+ }
+
+ ev_fds[ev_count].fd = fd;
+ ev_fds[ev_count].events = POLLIN;
+ ev_fdinfo[ev_count].cb = ev_cb;
+ ev_fdinfo[ev_count].data = data;
+ ev_count++;
+ ev_dev_count++;
+ if(ev_dev_count == MAX_DEVICES) break;
+ }
+ }
+
+ return 0;
+}
+
+void ev_exit(void)
+{
+ while (ev_count > 0) {
+ close(ev_fds[--ev_count].fd);
+ }
+ ev_misc_count = 0;
+ ev_dev_count = 0;
+}
+
+int ev_wait(int timeout)
+{
+ int r;
+
+ r = poll(ev_fds, ev_count, timeout);
+ if (r <= 0)
+ return -1;
+ return 0;
+}
+
+void ev_dispatch(void)
+{
+ unsigned n;
+// int ret;
+
+ for (n = 0; n < ev_count; n++) {
+ ev_callback cb = ev_fdinfo[n].cb;
+ if (cb && (ev_fds[n].revents & ev_fds[n].events))
+ cb(ev_fds[n].fd, ev_fds[n].revents, ev_fdinfo[n].data);
+ }
+}
+
+int ev_get_input(int fd, short revents, struct input_event *ev)
+{
+ int r;
+
+ if (revents & POLLIN) {
+ r = read(fd, ev, sizeof(*ev));
+ if (r == sizeof(*ev))
+ return 0;
+ }
+ return -1;
+}
+
+bool event_process(struct input_event ev)
+{
+ LOGI("Event:%d,%d,%d\n", ev.type, ev.code, ev.value);
+
+// if(ev.type != EV_KEY){
+// return false;
+// }
+
+ bool is_touch = true;
+ // Touch Down/Up
+ if(ev.type == EV_KEY && ev.code == BTN_TOUCH) {
+ if(!!ev.value) { // Down
+ action_down_get = true;
+ action_touched = true;
+ }
+ else // UP
+ {
+ action_down_get = false;
+ action_touched = false;
+ }
+ } else if(ev.type == EV_ABS) { // Touch move
+ if(!action_touched) // No down
+ return false;
+ } else if(ev.type != EV_KEY) {
+ return false;
+ } else {
+ is_touch = false;
+ }
+
+ if (!is_touch && ev.value < 2){ // 2 is long press events
+ int down = !!ev.value;
+ if (down){
+ LOGI("LongPress : DOWN.");
+ //if(!l->onKeyDown(ev.type, ev.code)) return false;
+ }else{
+ //if(!l->onKeyUp(ev.type, ev.code)) return false;
+ LOGI("LongPress : UP.");
+ }
+ } else if (is_touch) {
+ touch_event m_event;
+ if(ev.type == EV_ABS) { // Move
+ if(ev.code == KEY_SLASH) { // X
+ move_x = ev.value;
+ } else if(ev.code == KEY_RIGHTSHIFT) { // Y
+ if(action_down_get)
+ {
+ m_event.action = ACTION_DOWN;
+ action_down_get = false;
+ } else {
+ m_event.action = ACTION_MOVE;
+ }
+ m_event.x = move_x;
+ m_event.y = ev.value;
+
+ if(event_pre.x != m_event.x
+ || event_pre.y != m_event.y)
+ {
+ event_pre.x = m_event.x;
+ event_pre.y = m_event.y;
+ #ifdef MBTK_TP_RESIZE_SUPPORT
+ point_resize(getScreenWidth(),
+ getScreenHeight(),
+ mStatusBar->isVisibility() ? mStatusBar->getHeight() : 0,
+ &m_event);
+ #endif
+ LOGI("Window onTouchEvent action:%d (%d,%d) -> (%d,%d)",
+ m_event.action, event_pre.x, event_pre.y, m_event.x, m_event.y);
+
+ }
+ } else {
+ // Do nothing
+ }
+ } else if(!action_down_get){ // UP
+ m_event.action = ACTION_UP;
+ m_event.x = event_pre.x;
+ m_event.y = event_pre.y;
+
+ #ifdef MBTK_TP_RESIZE_SUPPORT
+ point_resize(getScreenWidth(),
+ getScreenHeight(),
+ mStatusBar->isVisibility() ? mStatusBar->getHeight() : 0,
+ &m_event);
+ #endif
+
+ LOGI("Window onTouchEvent action:%d (%d,%d) -> (%d,%d)",
+ m_event.action, event_pre.x, event_pre.y, m_event.x, m_event.y);
+
+ } else {
+ // Do nothing
+ }
+ } else {
+ // Do nothing
+ }
+
+ //invalidate();
+
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ // mbtk_log_init(NULL, "MBTK_EVENT");
+
+ if(ev_init(NULL)) {
+ LOGE("ev_init() fail.");
+ return -1;
+ }
+
+ LOGI("event getting...");
+ while(1) {
+ if(!ev_wait(-1))
+ ev_dispatch();
+ }
+
+ LOGI("exit!!!");
+ return 0;
+}
diff --git a/mbtk/test/others/uart_read_demo.c b/mbtk/test/others/uart_read_demo.c
new file mode 100755
index 0000000..1b7eea4
--- /dev/null
+++ b/mbtk/test/others/uart_read_demo.c
@@ -0,0 +1,185 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <string.h>
+
+#include "mbtk_type.h"
+#include "mbtk_log.h"
+
+#define DATABITS CS8
+#define STOPBITS 0
+#define PARITYON 0
+#define PARITY 0
+
+int uart_baud_get(int baud)
+{
+ int rate = 0;
+ switch(baud)
+ {
+ case 300:
+ rate = B300;
+ break;
+ case 600:
+ rate = B600;
+ break;
+ case 1200:
+ rate = B1200;
+ break;
+ case 2400:
+ rate = B2400;
+ break;
+ case 4800:
+ rate = B4800;
+ break;
+ case 9600:
+ rate = B9600;
+ break;
+ case 19200:
+ rate = B19200;
+ break;
+ case 38400:
+ rate = B38400;
+ break;
+ case 57600:
+ rate = B57600;
+ break;
+ case 115200:
+ rate = B115200;
+ break;
+ case 230400:
+ rate = B230400;
+ break;
+ case 460800:
+ rate = B460800;
+ break;
+ case 921600:
+ rate = B921600;
+ break;
+ case 1500000:
+ rate = B1500000;
+ break;
+ case 2000000:
+ rate = B2000000;
+ break;
+ case 3000000:
+ rate = B3000000;
+ break;
+ case 4000000:
+ rate = B4000000;
+ break;
+ default:
+ rate = B115200;
+ break;
+ }
+
+ return rate;
+}
+
+int gnss_port_open(const char *dev, int flag, int baud, bool tty)
+{
+
+ int fd = -1;
+ if((fd = open(dev, flag)) < 0)
+ {
+ printf("Open %s fail errno = [%d].\n", dev, errno);
+ return -1;
+ }
+
+ printf("Open %s success.\n", dev);
+ if (tty)
+ {
+ int rate = uart_baud_get(baud);
+ /* set newtio */
+ struct termios newtio;
+ memset(&newtio, 0, sizeof(newtio));
+ //(void)fcntl(fd, F_SETFL, 0);
+ /* no flow control for uart by default */
+ newtio.c_cflag = rate | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
+ newtio.c_iflag = IGNPAR;
+ //newtio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ newtio.c_oflag = 0;
+ newtio.c_lflag = 0; /* disable ECHO, ICANON, etc... */
+
+ newtio.c_cc[VERASE] = 0x8; /* del */
+ newtio.c_cc[VEOF] = 4; /* Ctrl-d */
+ newtio.c_cc[VMIN] = 1; /* blocking read until 1 character arrives */
+ newtio.c_cc[VEOL] = 0xD; /* '\0' */
+
+ tcflush(fd, TCIOFLUSH);
+ tcsetattr(fd, TCSANOW, &newtio);
+ }
+
+ return fd;
+}
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2) {
+ printf("%s <dev>\n", argv[1]);
+ return -1;
+ }
+
+ int fd = gnss_port_open(argv[1], O_RDWR | O_NONBLOCK | O_NOCTTY, 115200, TRUE);
+ if(fd < 0) {
+ printf("gnss_port_open(%s) fail:%d\n", argv[1], errno);
+ return -1;
+ }
+
+ char buff[1024];
+ int len, ret;
+ fd_set fdr;
+ FD_ZERO(&fdr);
+ FD_SET(fd, &fdr);
+
+ while(1) {
+ ret = select(fd + 1, &fdr, NULL, 0, NULL);
+ if (ret < 0)
+ {
+ if (errno == EINTR)
+ {
+ continue;
+ }
+ printf("select error, errno = %d (%s)\n", errno, strerror(errno));
+ break;
+ }
+ else if (ret == 0)
+ {
+ printf("select ret == 0\n");
+ break;
+ }
+
+ if (FD_ISSET(fd, &fdr))
+ {
+ memset(buff, 0, sizeof(buff));
+ len = read(fd, buff, sizeof(buff));
+ if(len > 0) {
+
+
+ } else if(len ==0 ){
+ printf("Read end : len = 0\n");
+ break;
+ } else {
+ if(EAGAIN == errno) {
+ usleep(50000);
+ continue;
+ } else {
+ printf("Read ret = -1 ,errno = %d\n", errno);
+ break;
+ }
+ }
+ }
+ else
+ {
+ printf("Unknown select event.\n");
+ continue;
+ }
+ }
+
+ printf("exit.\n");
+ return 0;
+}
+
+
diff --git a/mbtk/test/others/ubus_demo.c b/mbtk/test/others/ubus_demo.c
new file mode 100755
index 0000000..4806be3
--- /dev/null
+++ b/mbtk/test/others/ubus_demo.c
@@ -0,0 +1,79 @@
+#include <unistd.h>
+
+#include <libubox/blobmsg_json.h>
+#include "libubus.h"
+#include "mbtk_audio.h"
+
+void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg)
+{
+ printf("receive_call_result_data()\n");
+ if (!msg)
+ return;
+
+ printf("len - %d,data - %s\n", msg->id_len, msg->data);
+}
+
+
+int main(int argc, char *argv[])
+{
+#if 1
+ if(argc != 3) {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+ char *type = NULL;
+ int value = atoi(argv[2]);
+ if(!strcmp(argv[1], "switch")) {
+ type = "switch_pcm";
+ if(value != 0 && value != 1) {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+ } else if(!strcmp(argv[1], "mode")) {
+ type = "audio_mode_set";
+ if(value != -2 && value != 2) {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+ } else {
+ printf("ubus_demo switch/mode 0/1/-2/2\n");
+ return -1;
+ }
+
+ static struct ubus_context *ctx;
+ ctx = ubus_connect(NULL);
+ if (!ctx) {
+ printf("Failed to connect to ubus\n");
+ return -1;
+ }
+
+ static struct blob_buf b;
+ uint32_t id;
+ int ret;
+ ret = ubus_lookup_id(ctx, "audio_if", &id);
+ if (ret) {
+ printf("ubus_lookup_id() fail.\n");
+ return ret;
+ }
+
+
+
+ blob_buf_init(&b, 0);
+ blobmsg_add_u32(&b, "param0", value);
+ if((ret = ubus_invoke(ctx, id, type, b.head, NULL/*receive_call_result_data*/, NULL, 0)) != UBUS_STATUS_OK) {
+ printf("ubus_invoke fail:%d.\n", ret);
+ } else {
+ printf("ubus_invoke success.\n");
+ }
+#else
+
+ int handler = 0;
+ mbtk_audio_ubus_client_init(&handler, NULL);
+
+ mbtk_audio_switch_pcm(1);
+ mbtk_audio_mode_set(2);
+
+#endif
+
+ return 0;
+}
diff --git a/mbtk/test/others/usb_check.c b/mbtk/test/others/usb_check.c
new file mode 100755
index 0000000..7a8fc43
--- /dev/null
+++ b/mbtk/test/others/usb_check.c
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "mbtk_utils.h"
+
+static int running = 0;
+
+static void sig_handler(int sig)
+{
+ printf("Signal : %d\n", sig);
+ running = 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+ int fd = open("/tmp/usb.info", O_CREAT | O_WRONLY, 0666);
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+ if(fd > 0) {
+ char buff[1024];
+ running = 1;
+ while(running){
+ memset(buff, 0, 1024);
+ if(mbtk_cmd_line("cat /sys/class/android_usb/android0/state", buff, 1024)) {
+ mbtk_write(fd, buff, strlen(buff));
+ mbtk_write(fd, "\n", 1);
+ }
+ sleep(1);
+ }
+ close(fd);
+ }
+ return 0;
+}
+