/arch/arm/mach-msm/lge/lg_fw_diag_mtc.c
C | 837 lines | 566 code | 137 blank | 134 comment | 89 complexity | dc0f4de652c5edb0a5752d5fd18735ed MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
- /* arch/arm/mach-msm/lge/lg_fw_diag_mtc.c
- *
- * Copyright (C) 2009,2010 LGE, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
- #include <linux/module.h>
- #include <mach/lg_diagcmd.h>
- #include <mach/lg_fw_diag_mtc.h>
- #include <mach/lge_base64.h>
-
- #include <linux/unistd.h> /*for open/close */
- #include <linux/fcntl.h> /*for O_RDWR */
-
- #include <linux/fb.h> /* to handle framebuffer ioctls */
- #include <linux/ioctl.h>
- #include <linux/uaccess.h>
-
- #include <linux/syscalls.h> //for sys operations
-
- #include <linux/input.h> // for input_event
- #include <linux/fs.h> // for file struct
- #include <linux/types.h> // for ssize_t
- #include <linux/input.h> // for event parameters
- #include <linux/jiffies.h>
- #if 1 //LG_FW_MTC_GISELE
- #include <linux/crc-ccitt.h>
- #include <linux/delay.h>
-
- #define ESC_CHAR 0x7D
- #define CONTROL_CHAR 0x7E
- #define ESC_MASK 0x20
-
- #define CRC_16_L_SEED 0xFFFF
-
- #define CRC_16_L_STEP(xx_crc, xx_c) \
- crc_ccitt_byte(xx_crc, xx_c)
-
- void *lg_diag_mtc_req_pkt_ptr;
- unsigned short lg_diag_mtc_req_pkt_length;
-
- #endif //LG_FW_MTC_GISELE
-
- #ifndef LG_FW_DUAL_TOUCH
- #define LG_FW_DUAL_TOUCH
- #endif
-
- /*
- * EXTERNAL FUNCTION AND VARIABLE DEFINITIONS
- */
- extern PACK(void *) diagpkt_alloc(diagpkt_cmd_code_type code,
- unsigned int length);
- extern PACK(void *) diagpkt_free(PACK(void *)pkt);
- extern void send_to_arm9(void *pReq, void *pRsp);
-
- #if defined (CONFIG_MACH_MSM7X27_THUNDERC) || defined (LG_FW_ATS_ETA_MTC_KEY_LOGGING)
- extern unsigned int ats_mtc_log_mask;
- extern void diagpkt_commit(PACK(void *)pkt);
- #endif /*LG_FW_ATS_ETA_MTC_KEY_LOGGING */
-
-
- /*
- * LOCAL DEFINITIONS AND DECLARATIONS FOR MODULE
- *
- * This section contains local definitions for constants, macros, types,
- * variables and other items needed by this module.
- */
- #if defined (CONFIG_MACH_MSM7X27_THUNDERC) || defined (LG_FW_ATS_ETA_MTC_KEY_LOGGING)
- #define JIFFIES_TO_MS(t) ((t) * 1000 / HZ)
- #endif /*LG_FW_ATS_ETA_MTC_KEY_LOGGING */
-
- extern mtc_user_table_entry_type mtc_mstr_tbl[MTC_MSTR_TBL_SIZE];
-
- unsigned char g_diag_mtc_check = 0;
- static char mtc_running = 0;
- unsigned char g_diag_mtc_capture_rsp_num = 0;
-
- static mtc_lcd_info_type lcd_info;
-
- extern int diagchar_ioctl(unsigned int iocmd, unsigned long ioarg);
- static int ats_mtc_set_lcd_info(mtc_scrn_id_type ScreenType);
- static ssize_t read_framebuffer(byte * pBuf);
-
- typedef enum {
- /*
- * 0 Move pointer to the specified location
- * 1 Move the pointer by the specified values
- * 2 Tap at the current location
- * 3 Double tap at the current location
- * 4 Touch down at the current location
- * 5 Touch up at the current location
- * */
- MOVE_ABSOLUTE,
- MOVE_RELATIVE,
- TAP,
- DOUBLE_TAP,
- TOUCH_DOWN,
- TOUCH_UP
- } TOUCH_ACTIONS;
-
- #if 1 //LG_FW_MTC_GISELE
- /*
- * FUNCTION add_hdlc_packet.
- */
- static void add_hdlc_packet(struct mtc_data_buffer *mb, char data)
- {
- mb->data[mb->data_length++] = data;
-
- //if (mb->data_length == BUFFER_MAX_SIZE) {
- if (mb->data_length >= BUFFER_MAX_SIZE) {
- mb->data_length = BUFFER_MAX_SIZE;
-
- msleep(10);
-
- if (diagchar_ioctl (DIAG_IOCTL_BULK_DATA, (unsigned long)mb)) {
- printk(KERN_ERR "[MTC] %s: diagchar_ioctl error\n", __func__);
- }
-
- mb->data_length = 0;
- }
- }
-
- /*
- * FUNCTION add_hdlc_esc_packet.
- */
- static void add_hdlc_esc_packet(struct mtc_data_buffer *mb, char data)
- {
- if (data == ESC_CHAR || data == CONTROL_CHAR) {
- add_hdlc_packet(mb, ESC_CHAR);
- add_hdlc_packet(mb, (data ^ ESC_MASK));
- }
- else {
- add_hdlc_packet(mb, data);
- }
- }
-
- /*
- * FUNCTION mtc_send_hdlc_packet.
- */
- static void mtc_send_hdlc_packet(byte * pBuf, int len)
- {
- int i;
- struct mtc_data_buffer *mb;
- word crc = CRC_16_L_SEED;
-
- mb = kzalloc(sizeof(struct mtc_data_buffer), GFP_ATOMIC);
- if (mb == NULL) {
- printk(KERN_ERR "[MTC] %s: failed to alloc memory\n", __func__);
- return;
- }
-
- //Generate crc data.
- for (i = 0; i < len; i++) {
- add_hdlc_esc_packet(mb, pBuf[i]);
- crc = CRC_16_L_STEP(crc, (word) pBuf[i]);
- }
-
- crc ^= CRC_16_L_SEED;
- add_hdlc_esc_packet(mb, ((unsigned char)crc));
- add_hdlc_esc_packet(mb, ((unsigned char)((crc >> 8) & 0xFF)));
- add_hdlc_packet(mb, CONTROL_CHAR);
-
- if (diagchar_ioctl(DIAG_IOCTL_BULK_DATA, (unsigned long)mb)) {
- printk(KERN_ERR "[MTC] %s: ioctl ignored\n", __func__);
- }
-
- kfree(mb);
- mb = NULL;
- }
-
-
- /*
- * FUNCTION translate_key_code.
- */
- dword translate_key_code(dword keycode)
- {
- if (keycode == KERNELFOCUSKEY)
- return KERNELCAMERAKEY;
- else
- return keycode;
-
- }
-
- /*
- * FUNCTION mtc_send_key_log_packet.
- */
- void mtc_send_key_log_packet(unsigned long keycode, unsigned long state)
- {
- ext_msg_type msg;
- dword sendKeyValue = 0;
-
- /* LGE_CHANGE [dojip.kim@lge.com] 2010-06-04 [LS670]
- * don't send a raw diag packet in running MTC
- */
- if (mtc_running)
- return;
-
- memset(&msg, 0, sizeof(ext_msg_type));
-
- sendKeyValue = translate_key_code(keycode);
-
- msg.cmd_code = 121;
- msg.ts_type = 0; //2;
- msg.num_args = 2;
- msg.drop_cnt = 0;
- //ts_get(&msg.time[0]);
- msg.time[0] = 0;
- msg.time[1] = 0;
- msg.line_number = 261;
- msg.ss_id = 0;
- msg.ss_mask = 2;
- msg.args[0] = sendKeyValue;
- msg.args[1] = state;
-
- memcpy(&msg.code[0], "Debounced %d", sizeof("Debounced %d"));
- //msg.code[12] = '\0';
-
- memcpy(&msg.file_name[0], "DiagDaemon.c", sizeof("DiagDaemon.c"));
- //msg.fle_name[13] = '\0';
-
- mtc_send_hdlc_packet((byte *) & msg, sizeof(ext_msg_type));
- }
-
- EXPORT_SYMBOL(mtc_send_key_log_packet);
- #endif //LG_FW_MTC_GISELE
-
- /*
- * INTERNAL FUNCTION DEFINITIONS
- */
- PACK(void *) LGF_MTCProcess(PACK(void *)req_pkt_ptr,/* pointer to request packet */
- unsigned short pkt_len)
- { /* length of request packet */
- DIAG_MTC_F_req_type *req_ptr = (DIAG_MTC_F_req_type *) req_pkt_ptr;
- DIAG_MTC_F_rsp_type *rsp_ptr = NULL;
- mtc_func_type func_ptr = NULL;
- int nIndex = 0;
- g_diag_mtc_check = 1;
- mtc_running = 1;
-