boolean Diag_LSM_Init (byte* pParam) { if(qurt_atomic_compare_and_set(&diag_lsm_ref_count_mutex_init, FALSE, TRUE)) { qurt_rmutex_init(&diag_lsm_ref_count_mutex); } qurt_rmutex_lock(&diag_lsm_ref_count_mutex); if (0 == gnDiag_LSM_Ref_Count) { diag_pid = qurt_getpid(); if (0 > diag_qdi_handle) { diag_qdi_handle = qurt_qdi_open("/dev/diag"); if(diag_qdi_handle<0) { printf(" Diag_LSM_Init : QDI open failed\n"); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } } if(!DiagSvc_Malloc_Init()) { printf("Diag_LSM_Init : SVC malloc failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } if(!CreateWaitThread()) { printf("Diag_LSM_Init : createwaitthread failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } if(!Diag_LSM_Log_Init()) { printf("Diag_LSM_Init : lsm log init failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } if(!Diag_LSM_Event_Init()) { printf("Diag_LSM_Init : lsm event init failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } if(!Diag_LSM_Msg_Init()) { printf("Diag_LSM_Init : lsm msg init failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } if(!Diag_LSM_Pkt_Init()) { printf("Diag_LSM_Init : lsm pkt init failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } #ifdef FEATURE_DIAG_STM diag_stm_init(); #endif if(!RegisterForMaskChange(MASK_CHANGE_REGISTER)) { printf("Diag_LSM_Init : registerformaskchange failed\n"); Diag_LSM_DeInit(); qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return FALSE; } } /*end if(!InterlockedCompareExchange(&gnDiag_LSM_Ref_Count,1,0) */ gnDiag_LSM_Ref_Count += 1; qurt_rmutex_unlock(&diag_lsm_ref_count_mutex); return TRUE; } /* Diag_LSM_Init */
int32_t main(int32_t argc, char *argv[]) { int res =0; uint8_t *eventbuf = NULL; uint8_t *dbgbuf = NULL; int32_t c; struct dbglog_slot *slot; int cnss_intf_len = strlen(CNSS_INTF) + 1; pthread_t thd_id; progname = argv[0]; uint16_t diag_type = 0; int32_t option_index = 0; static struct option long_options[] = { {"logfile", 1, NULL, 'f'}, {"reclimit", 1, NULL, 'r'}, {"console", 0, NULL, 'c'}, {"qxdm", 0, NULL, 'q'}, {"silent", 0, NULL, 's'}, {"debug", 0, NULL, 'd'}, { 0, 0, 0, 0} }; while (1) { c = getopt_long (argc, argv, "f:scqdr:", long_options, &option_index); if (c == -1) break; switch (c) { case 'f': memset(dbglogoutfile, 0, PATH_MAX); memcpy(dbglogoutfile, optarg, strlen(optarg)); optionflag |= LOGFILE_FLAG; break; case 'c': optionflag |= CONSOLE_FLAG; break; case 'q': optionflag |= QXDM_FLAG; break; case 'r': rec_limit = strtoul(optarg, NULL, 0); break; case 's': optionflag |= SILENT_FLAG; break; case 'd': optionflag |= DEBUG_FLAG; break; default: usage(); } } if (!(optionflag & (LOGFILE_FLAG | CONSOLE_FLAG | QXDM_FLAG | SILENT_FLAG | DEBUG_FLAG))) { usage(); return -1; } if (optionflag & QXDM_FLAG) { /* Intialize the fd required for diag APIs */ if (TRUE != Diag_LSM_Init(NULL)) { perror("Failed on Diag_LSM_Init\n"); return -1; } /* Register CALLABACK for QXDM input data */ DIAGPKT_DISPATCH_TABLE_REGISTER(DIAG_SUBSYS_WLAN, cnss_wlan_tbl); #ifdef ANDROID if(cnssdiagservice_cap_handle()) { printf("Cap bouncing failed EXIT!!!"); exit(1); } #endif } pthread_create(&thd_id, NULL, &cnss_intf_wait_receive, NULL); sock_fd = create_nl_socket(); if (sock_fd < 0) { fprintf(stderr, "Socket creation failed sock_fd 0x%x \n", sock_fd); return -1; } if (is_interface(CNSS_INTF, cnss_intf_len)) { initialize(sock_fd); cnssdiag_register_kernel_logging(sock_fd, nlh); } signal(SIGINT, stop); signal(SIGTERM, stop); if (optionflag & LOGFILE_FLAG) { if (rec_limit < RECLEN) { fprintf(stderr, "Too small maximum length (has to be >= %d)\n", RECLEN); close(sock_fd); free(nlh); return -1; } max_records = rec_limit; printf("Storing last %d records\n", max_records); log_out = fopen(dbglogoutfile, "w"); if (log_out == NULL) { perror("Failed to create output file"); close(sock_fd); free(nlh); return -1; } fwlog_res_file = "./reorder"; } parser_init(); while ( 1 ) { if ((res = recvmsg(sock_fd, &msg, 0)) < 0) continue; if ((res >= (int)sizeof(struct dbglog_slot)) || (nlh->nlmsg_type == WLAN_NL_MSG_CNSS_HOST_EVENT_LOG)) { process_cnss_diag_msg((tAniNlHdr *)nlh); memset(nlh,0,NLMSG_SPACE(MAX_MSG_SIZE)); } else { /* Ignore other messages that might be broadcast */ continue; } } /* Release the handle to Diag*/ Diag_LSM_DeInit(); if (optionflag & LOGFILE_FLAG) cleanup(); close(sock_fd); free(nlh); return 0; }