// Compare Functions int IString_Strcmp ( IStringPtr self, ZString str2 ) { ESIF_ASSERT(self); if (self->buf_ptr && str2) { return esif_ccb_strcmp((ZString)self->buf_ptr, str2); } return 0; }
EsifString GetDSPFromList( EsifString name ) { EsifString selection = NULL; UInt32 item = 0; for (item = 0; dsp_mapping[item].dsp_name != NULL; item++) { if (dsp_mapping[item].name == NULL || esif_ccb_strcmp(dsp_mapping[item].name, name) == 0) { selection = dsp_mapping[item].dsp_name; break; } } return selection; }
// Compare two IStrings int IString_Compare ( IStringPtr self, IStringPtr str2, int IgnoreCase ) { if (self && str2 && self->buf_ptr && str2->buf_ptr) { if (IgnoreCase) { return esif_ccb_stricmp((ZString)self->buf_ptr, (ZString)str2->buf_ptr); } else { return esif_ccb_strcmp((ZString)self->buf_ptr, (ZString)str2->buf_ptr); } } return 0; }
// IPC Connect eEsifError ipc_connect() { eEsifError rc = ESIF_OK; int check_kernel_version = ESIF_TRUE; ESIF_TRACE_ENTRY_INFO(); // Exit if IPC already connected if (g_ipc_handle != ESIF_INVALID_HANDLE) { return ESIF_OK; } // Connect to LF g_ipc_handle = esif_ipc_connect((char *)SESSION_ID); if (g_ipc_handle == ESIF_INVALID_HANDLE) { ESIF_TRACE_WARN("ESIF LF is not available\n"); rc = ESIF_E_NO_LOWER_FRAMEWORK; } else { char *outbuf = esif_ccb_malloc(OUT_BUF_LEN); char *kern_str = (outbuf != NULL ? esif_cmd_info(outbuf) : NULL); ESIF_TRACE_DEBUG("ESIF IPC Kernel Device Opened\n"); if (NULL != kern_str) { // Extract just the Kernel LF Version from the result string extract_kernel_version(kern_str, OUT_BUF_LEN); // Bypass Kernel Version check for DEBUG builds #if defined(ESIF_ATTR_DEBUG) check_kernel_version = ESIF_FALSE; #endif // Validate Kernel LF version is compatible with UF version if (check_kernel_version == ESIF_FALSE || esif_ccb_strcmp(kern_str, ESIF_VERSION) == 0) { ESIF_TRACE_INFO("Kernel Version: %s\n", kern_str); esif_ccb_sprintf(sizeof(g_esif_kernel_version), g_esif_kernel_version, "%s", kern_str); } else { ESIF_TRACE_ERROR("ESIF_LF Version (%s) Incompatible with ESIF_UF Version (%s)\n", kern_str, ESIF_VERSION); ipc_disconnect(); rc = ESIF_E_NOT_SUPPORTED; } } esif_ccb_free(outbuf); } ESIF_TRACE_EXIT_INFO_W_STATUS(rc); return rc; }
/* Data For Interface Marshaling */ static AppDataPtr CreateAppData(esif_string pathBuf) { AppDataPtr app_data_ptr = NULL; char policyPath[ESIF_PATH_LEN] = { 0 }; if (NULL == pathBuf) { ESIF_TRACE_ERROR("Path buffer is NULL\n"); goto exit; } /* Build path(s) for DPTF: "HomeDir" or "HomeDir|[#]PolicyDir" */ esif_build_path(pathBuf, ESIF_PATH_LEN, ESIF_PATHTYPE_DPTF, NULL, NULL); esif_build_path(policyPath, sizeof(policyPath), ESIF_PATHTYPE_DLL, NULL, NULL); if (esif_ccb_strcmp(pathBuf, policyPath) != 0) { char policyDummyPath[ESIF_PATH_LEN] = { 0 }; /* empty if path starts with "#" */ esif_build_path(policyDummyPath, sizeof(policyDummyPath), ESIF_PATHTYPE_DLL, "", NULL); esif_ccb_sprintf_concat(ESIF_PATH_LEN, pathBuf, "|%s%s", (policyDummyPath[0] ? "" : "#"), policyPath); } ESIF_TRACE_DEBUG("pathBuf=%s\n\n", (esif_string)pathBuf); app_data_ptr = (AppDataPtr)esif_ccb_malloc(sizeof(AppData)); if (NULL == app_data_ptr) { ESIF_TRACE_ERROR("Fail to allocate AppData\n"); goto exit; } app_data_ptr->fPathHome.buf_ptr = (void *)pathBuf; app_data_ptr->fPathHome.buf_len = ESIF_PATH_LEN; app_data_ptr->fPathHome.data_len = (UInt32)esif_ccb_strlen(pathBuf, ESIF_PATH_LEN); app_data_ptr->fPathHome.type = ESIF_DATA_STRING; app_data_ptr->fLogLevel = (eLogType) g_traceLevel; exit: return app_data_ptr; }
static int esif_ws_http_process_static_pages ( ClientRecordPtr connection, char *buffer, char *resource, ssize_t ret, char *fileType ) { struct stat st={0}; char tmpbuffer[128]={0}; char file_to_open[MAX_PATH]={0}; char content_disposition[MAX_PATH]={0}; FILE *file_fp = NULL; esif_build_path(file_to_open, sizeof(file_to_open), ESIF_PATHTYPE_UI, resource, NULL); esif_ccb_fopen(&file_fp, (esif_string)file_to_open, (esif_string)"rb"); // Log file workaround: If not found in HTML folder, look in LOG folder if (NULL == file_fp) { char logpath[MAX_PATH]={0}; esif_build_path(logpath, sizeof(logpath), ESIF_PATHTYPE_LOG, resource, NULL); esif_ccb_fopen(&file_fp, (esif_string)logpath, (esif_string)"rb"); if (NULL != file_fp) esif_ccb_strcpy(file_to_open, logpath, sizeof(file_to_open)); } ESIF_TRACE_DEBUG("HTTP: file=%s, type=%s\n", file_to_open, fileType); if (NULL == file_fp) { ESIF_TRACE_DEBUG("failed to open file: %s\n", file_to_open); return 404; } if (esif_ccb_stat(file_to_open, &st) != 0) { ESIF_TRACE_DEBUG("Could not stat file descriptor \n"); fclose(file_fp); return 404; } fseek(file_fp, (off_t)0, SEEK_END); fseek(file_fp, (off_t)0, SEEK_SET); // Add Content-Disposition header to prompt user with Save-As Dialog if unknown file type if (esif_ccb_strcmp(fileType, UNKNOWN_MIME_TYPE) == 0) { esif_ccb_sprintf(sizeof(content_disposition), content_disposition, "Content-Disposition: attachment; filename=\"%s\";\n", resource); } esif_ccb_sprintf(WS_BUFFER_LENGTH, buffer, "HTTP/1.1 200 OK\n" "Server: ESIF_UF/%s\n" "Last-Modified: %s\n" "Date: %s\n" "Content-Type: %s\n" "Content-Length: %ld\n" "%s" "Connection: close\n" "\n", ESIF_UF_VERSION, esif_ws_http_time_stamp(st.st_mtime, tmpbuffer), esif_ws_http_time_stamp(time(0), tmpbuffer), fileType, (long)st.st_size, content_disposition); send(connection->socket, buffer, (int)esif_ccb_strlen(buffer, WS_BUFFER_LENGTH), ESIF_WS_SEND_FLAGS); while ((ret = (int)fread(buffer, 1, WS_BUFFER_LENGTH, file_fp)) > 0) { send(connection->socket, buffer, (int)ret, ESIF_WS_SEND_FLAGS); } fclose(file_fp); return 0; }
static int esif_ws_server_create_inet_addr( void *addrPtr, socklen_t *addrlenPtr, char *hostPtr, char *portPtr, char *protPtr ) { struct sockaddr_in *sockaddr_inPtr = (struct sockaddr_in*)addrPtr; struct hostent *hostenPtr = NULL; struct servent *serventPtr = NULL; char *endStr; long longVal; if (!hostPtr) { hostPtr = (char*)"*"; } if (!portPtr) { portPtr = (char*)"*"; } if (!protPtr) { protPtr = (char*)"tcp"; } esif_ccb_memset(sockaddr_inPtr, 0, *addrlenPtr); sockaddr_inPtr->sin_family = AF_INET; sockaddr_inPtr->sin_port = 0; sockaddr_inPtr->sin_addr.s_addr = INADDR_ANY; if (esif_ccb_strcmp(hostPtr, "*") == 0) { ; } else if (isdigit(*hostPtr)) { sockaddr_inPtr->sin_addr.s_addr = inet_addr(hostPtr); if (sockaddr_inPtr->sin_addr.s_addr == INADDR_NONE) { return -1; } } else { hostenPtr = gethostbyname(hostPtr); if (!hostenPtr) { return -1; } if (hostenPtr->h_addrtype != AF_INET) { return -1; } sockaddr_inPtr->sin_addr = *(struct in_addr*) hostenPtr->h_addr_list[0]; } if (!esif_ccb_strcmp(portPtr, "*")) { ; } else if (isdigit(*portPtr)) { longVal = strtol(portPtr, &endStr, 10); if (endStr != NULL && *endStr) { return -2; } if (longVal < 0L || longVal >= 32768) { return -2; } sockaddr_inPtr->sin_port = htons((short)longVal); } else { serventPtr = getservbyname(portPtr, protPtr); if (!serventPtr) { return -2; } sockaddr_inPtr->sin_port = (short)serventPtr->s_port; } *addrlenPtr = sizeof *sockaddr_inPtr; return 0; }
static eEsifError EsifDataLogValidateParticipantList(char *inParticipantList) { int i = 0; char *participantList = NULL; char *participantSelect = NULL; char colDelims [] = ","; char *partTok = NULL; UInt8 participantId = 0; int participantCounter = 0; int totalFields = 0; eEsifError rc = ESIF_OK; for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++){ g_dataLogParticipants[i].participantId = 0; g_dataLogParticipants[i].participantNumFields = 0; } if (inParticipantList == NULL) { for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) { EsifUpPtr upPtr = NULL; participantId = (UInt8) i; upPtr = EsifUpPm_GetAvailableParticipantByInstance(participantId); if (NULL != upPtr) { int j = 0; int fieldCounter = 0; struct esif_fpc_domain *domainPtr = NULL; UInt8 domainCount = (u8)upPtr->fDspPtr->get_domain_count(upPtr->fDspPtr); DataLogParticipant nextParticipant = { 0 }; for (j = 0; j < domainCount; j++) { domainPtr = upPtr->fDspPtr->get_domain(upPtr->fDspPtr, j + 1); if (NULL == domainPtr) { continue; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_TEMP_STATUS) { fieldCounter += 4; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_POWER_CONTROL) { fieldCounter += 2; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_ACTIVE_CONTROL) { fieldCounter += 1; } } nextParticipant.participantId = participantId; nextParticipant.participantNumFields = fieldCounter; g_dataLogParticipants[participantCounter] = nextParticipant; totalFields += fieldCounter; EsifUp_PutRef(upPtr); participantCounter++; } } goto exit; } if (esif_ccb_strlen(inParticipantList, MAX_LOG_LINE) >= 1) { participantList = esif_ccb_strdup(inParticipantList); participantSelect = esif_ccb_strtok(participantList, colDelims, &partTok); while (participantSelect != NULL) { EsifUpPtr upPtr = { 0 }; if (participantCounter >= (sizeof(g_dataLogParticipants)/sizeof(*g_dataLogParticipants))) { rc = ESIF_E_NOT_SUPPORTED; goto exit; } if ((int)esif_atoi(participantSelect) > 0 || esif_ccb_strcmp(participantSelect, "0") == 0) { participantId = (UInt8) esif_atoi(participantSelect); upPtr = EsifUpPm_GetAvailableParticipantByInstance(participantId); } else { upPtr = EsifUpPm_GetAvailableParticipantByName(participantSelect); } if (NULL == upPtr) { rc = ESIF_E_PARTICIPANT_NOT_FOUND; goto exit; } else { int j = 0; int fieldCounter = 0; struct esif_fpc_domain *domainPtr = NULL; UInt8 domainCount = (u8) upPtr->fDspPtr->get_domain_count(upPtr->fDspPtr); DataLogParticipant nextParticipant = { 0 }; participantId = (UInt8) upPtr->fInstance; /* redundant in the case of an id passed in, but needed for name*/ for (j = 0; j < domainCount; j++) { domainPtr = upPtr->fDspPtr->get_domain(upPtr->fDspPtr, j + 1); if (NULL == domainPtr) { continue; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_TEMP_STATUS) { fieldCounter += 4; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_POWER_CONTROL) { fieldCounter += 2; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_ACTIVE_CONTROL) { fieldCounter += 1; } } nextParticipant.participantId = participantId; nextParticipant.participantNumFields = fieldCounter; g_dataLogParticipants[participantCounter] = nextParticipant; totalFields += fieldCounter; EsifUp_PutRef(upPtr); participantCounter++; } participantSelect = esif_ccb_strtok(NULL, colDelims, &partTok); } } else { for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) { EsifUpPtr upPtr = NULL; participantId = (UInt8) i; upPtr = EsifUpPm_GetAvailableParticipantByInstance(participantId); if (NULL != upPtr) { int j = 0; int fieldCounter = 0; struct esif_fpc_domain *domainPtr = NULL; UInt8 domainCount = (u8)upPtr->fDspPtr->get_domain_count(upPtr->fDspPtr); DataLogParticipant nextParticipant = { 0 }; for (j = 0; j < domainCount; j++) { domainPtr = upPtr->fDspPtr->get_domain(upPtr->fDspPtr, j + 1); if (NULL == domainPtr) { continue; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_TEMP_STATUS) { fieldCounter += 4; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_POWER_CONTROL) { fieldCounter += 2; } if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_ACTIVE_CONTROL) { fieldCounter += 1; } } nextParticipant.participantId = participantId; nextParticipant.participantNumFields = fieldCounter; g_dataLogParticipants[participantCounter] = nextParticipant; totalFields += fieldCounter; EsifUp_PutRef(upPtr); participantCounter++; } } } exit: esif_ccb_free(participantList); if (totalFields == 0) { rc = ESIF_E_NOT_SUPPORTED; } return rc; }