| /* |
| * All Rights Reserved |
| * |
| * MARVELL CONFIDENTIAL |
| * Copyright 2012 Marvell International Ltd All Rights Reserved. |
| * The source code contained or described herein and all documents related to |
| * the source code ("Material") are owned by Marvell International Ltd or its |
| * suppliers or licensors. Title to the Material remains with Marvell International Ltd |
| * or its suppliers and licensors. The Material contains trade secrets and |
| * proprietary and confidential information of Marvell or its suppliers and |
| * licensors. The Material is protected by worldwide copyright and trade secret |
| * laws and treaty provisions. No part of the Material may be used, copied, |
| * reproduced, modified, published, uploaded, posted, transmitted, distributed, |
| * or disclosed in any way without Marvell's prior express written permission. |
| * |
| * No license under any patent, copyright, trade secret or other intellectual |
| * property right is granted to or conferred upon you by disclosure or delivery |
| * of the Materials, either expressly, by implication, inducement, estoppel or |
| * otherwise. Any license under such intellectual property rights must be |
| * express and approved by Marvell in writing. |
| * |
| */ |
| |
| #define LOG_TAG "slic_ctrl_server" |
| |
| #include <cutils/log.h> |
| #include <cutils/properties.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <sys/prctl.h> |
| #include <sys/socket.h> |
| #include <unistd.h> |
| #include <pthread.h> |
| #include <errno.h> |
| #include <sys/un.h> |
| #include <stddef.h> |
| |
| #include "SLICApp.h" |
| #include "slic_ctrl_server.h" |
| |
| static pthread_t slic_ctrl_Server_t; |
| |
| extern volatile int g_SLICAPP_Dump_Registers; |
| extern volatile int g_SLICAPP_Read_Register; |
| extern volatile int g_SLICAPP_Write_Register; |
| extern volatile int g_SLICAPP_Cycle_Read_Registers; |
| extern volatile int g_SLICAPP_Cycle_Write_Register; |
| extern uInt8 g_SLICAPP_reg_addr; |
| extern uInt8 g_SLICAPP_reg_value; |
| |
| //server to handle the message from client which is from CATSTUDIO tools .... |
| static void slic_ctrl_server_thread(void *data) { |
| (void)data; |
| unsigned int len; |
| int fd = -1; |
| int clientfd = -1; |
| struct sockaddr_un un; |
| SLIC_CTRL_IPC_Package rcv_buf; |
| |
| prctl(15,"slic_ctrl_server"); |
| /* create a UNIX domain stream socket */ |
| if ((fd = socket(AF_UNIX, SOCK_SEQPACKET, 0)) < 0) { |
| LOG_OUT_E("[%s][%d][create socket fail]\n", __FUNCTION__, __LINE__); |
| return; |
| } |
| |
| unlink(SLIC_CTRL_SOCKET); /* in case it already exists */ |
| |
| /* fill in socket address structure */ |
| memset(&un, 0, sizeof(un)); |
| un.sun_family = AF_UNIX; |
| strcpy(un.sun_path, SLIC_CTRL_SOCKET); |
| len = offsetof(struct sockaddr_un, sun_path) + strlen(SLIC_CTRL_SOCKET); |
| |
| LOG_OUT("%s/L%d: addr=%s.\n", __FUNCTION__, __LINE__, un.sun_path); |
| |
| /* bind the name to the descriptor */ |
| if (bind(fd, (struct sockaddr *)&un, len) < 0) { |
| |
| LOG_OUT_E("[%s][%d][bind fail][error %d (%s)]\n" \ |
| , __FUNCTION__, __LINE__,errno, strerror(errno)); |
| close(fd); |
| return; |
| } |
| |
| if (chmod(SLIC_CTRL_SOCKET, 0666) < 0) { |
| LOG_OUT_E("[%s][%d]FAIL to chmod SLIC_CTRL_SOCKET to 0666\n", __FUNCTION__, __LINE__); |
| close(fd); |
| return; |
| } |
| |
| if (listen(fd, QLEN) < 0) { /* tell kernel we're a server */ |
| LOG_OUT_E("[%s][%d][listen fail]\n", __FUNCTION__, __LINE__); |
| close(fd); |
| return; |
| } |
| |
| while(1) { |
| len = sizeof(un); |
| //close last connection |
| if (clientfd >= 0) { |
| close(clientfd); |
| clientfd = -1; |
| //usleep(10000); /* must be deleted */ |
| } |
| |
| if ((clientfd = accept(fd, (struct sockaddr *)&un, &len)) < 0) { |
| LOG_OUT_E("%s/L%d: accept fail\n", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| if(read(clientfd, &rcv_buf, sizeof(rcv_buf))==-1) { |
| LOG_OUT_E("%s/L%d: read fail\n", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| LOG_OUT("%s/L%d: [receive type:0x%lx]-[d1:0x%lx][d2:0x%lx][d3:0x%lx][d4:0x%lx]\n", |
| __FUNCTION__, __LINE__, |
| rcv_buf.type, rcv_buf.body.d1, rcv_buf.body.d2, rcv_buf.body.d3, rcv_buf.body.d4); |
| |
| switch (rcv_buf.type) { |
| case SLIC_CTRL_DUMP_REGISTERS: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_Dump_Registers = TRUE; |
| |
| /* stop the other operations about registers */ |
| g_SLICAPP_Read_Register = FALSE; |
| g_SLICAPP_Write_Register = FALSE; |
| g_SLICAPP_Cycle_Read_Registers = FALSE; |
| g_SLICAPP_Cycle_Write_Register = FALSE; |
| |
| ret_slic = 0; |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| |
| case SLIC_CTRL_READ_REGISTER: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_reg_addr = (uInt8)(rcv_buf.body.d1 & 0xFF); |
| g_SLICAPP_Read_Register = TRUE; |
| |
| /* stop the other operations about registers */ |
| g_SLICAPP_Dump_Registers = FALSE; |
| g_SLICAPP_Write_Register = FALSE; |
| g_SLICAPP_Cycle_Read_Registers = FALSE; |
| g_SLICAPP_Cycle_Write_Register = FALSE; |
| |
| ret_slic = 0; |
| |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| |
| case SLIC_CTRL_WRITE_REGISTER: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_reg_addr = (uInt8)(rcv_buf.body.d1 & 0xFF); |
| g_SLICAPP_reg_value = (uInt8)(rcv_buf.body.d2 & 0xFF); |
| g_SLICAPP_Write_Register = TRUE; |
| |
| /* stop the other operations about registers */ |
| g_SLICAPP_Dump_Registers = FALSE; |
| g_SLICAPP_Read_Register = FALSE; |
| g_SLICAPP_Cycle_Read_Registers = FALSE; |
| g_SLICAPP_Cycle_Write_Register = FALSE; |
| |
| ret_slic = 0; |
| |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| |
| case SLIC_CTRL_START_CYCLE_READ_REGISTER: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_reg_addr = (uInt8)(rcv_buf.body.d1 & 0xFF); |
| g_SLICAPP_Cycle_Read_Registers = TRUE; |
| |
| /* stop the other operations about registers */ |
| g_SLICAPP_Dump_Registers = FALSE; |
| g_SLICAPP_Read_Register = FALSE; |
| g_SLICAPP_Write_Register = FALSE; |
| g_SLICAPP_Cycle_Write_Register = FALSE; |
| |
| ret_slic = 0; |
| |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| |
| case SLIC_CTRL_START_CYCLE_WRITE_REGISTER: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_reg_addr = (uInt8)(rcv_buf.body.d1 & 0xFF); |
| g_SLICAPP_reg_value = (uInt8)(rcv_buf.body.d2 & 0xFF); |
| g_SLICAPP_Cycle_Write_Register = TRUE; |
| |
| /* stop the other operations about registers */ |
| g_SLICAPP_Dump_Registers = FALSE; |
| g_SLICAPP_Read_Register = FALSE; |
| g_SLICAPP_Write_Register = FALSE; |
| g_SLICAPP_Cycle_Read_Registers = FALSE; |
| |
| ret_slic = 0; |
| |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| |
| case SLIC_CTRL_STOP_CYCLE_READ_REGISTER: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_Cycle_Read_Registers = FALSE; |
| |
| ret_slic = 0; |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| |
| case SLIC_CTRL_STOP_CYCLE_WRITE_REGISTER: |
| { |
| int ret_slic = -1; |
| |
| g_SLICAPP_Cycle_Write_Register = FALSE; |
| |
| ret_slic = 0; |
| if(write(clientfd, &ret_slic, sizeof(int)) == -1) |
| { |
| LOG_OUT_E("%s/L%d: write failed!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| |
| break; |
| } |
| default: |
| LOG_OUT_E("%s/L%d: type is error!", __FUNCTION__, __LINE__); |
| continue; |
| } |
| } |
| |
| unlink(SLIC_CTRL_SOCKET); |
| return; |
| } |
| |
| |
| void slic_ctrl_server_IPC(void) |
| { |
| pthread_create( &slic_ctrl_Server_t, NULL, (void *)slic_ctrl_server_thread, NULL); |
| } |