static void os_dump_seminfo() { int i = 0, temp; const unsigned int *px_queue = NULL; unsigned int *list; char *pc_write_buffer = os_mem_alloc(MAX_WAITER_BUF); if (pc_write_buffer == NULL) return; if (sem_mutex) { temp = os_mutex_get(&sem_mutex, OS_WAIT_FOREVER); if (temp == -WM_FAIL) { wmprintf("[sem-dbg] Failed to get sem-mutex\r\n"); os_mem_free(pc_write_buffer); return; } } if (semcnt > 0) { wmprintf("%-32s%-8s%-50s%s", "Name", "Count", "Waiters", "Type\r\n"); } for (i = 0; i < MAX_SEM_INFO_BUF; i++) { if (semdbg[i].x_queue == 0) continue; if (semdbg[i].q_name && isascii(semdbg[i].q_name[0])) { wmprintf("%-32s", semdbg[i].q_name); } else { wmprintf("%-32s", "-"); } px_queue = semdbg[i].x_queue; wmprintf("%-8d", os_semaphore_getcount(&semdbg[i].x_queue)); vGetWaiterListFromHandle(px_queue, &list); vGetTaskNamesInList((signed char *) pc_write_buffer, MAX_WAITER_BUF - 1, (const unsigned int *)list); pc_write_buffer[MAX_WAITER_BUF - 1] = '\0'; wmprintf("%-50s ", pc_write_buffer); (semdbg[i].is_semaphore == 0) ? wmprintf("q") : wmprintf("s"); wmprintf("\r\n"); } if (sem_mutex) os_mutex_put(&sem_mutex); os_mem_free(pc_write_buffer); }
void tls_close(tls_handle_t *h) { tls_d("Close session"); ASSERT(h != NULL); ASSERT(*h != 0); tls_session_t *s = (tls_session_t *) *h; ASSERT(s->session_setup_done == true); /* Check whether s is valid or not * because WPS module calls tls_close * from multiple locations during WPA2 * Enterprise negotiation. */ if (!s) return; if (s->ssl) { SSL_shutdown(s->ssl); SSL_free(s->ssl); } if (s->ctx) SSL_CTX_free(s->ctx); s->session_setup_done = false; os_mem_free(s); *h = 0; }
int tls_session_init(tls_handle_t *h, int sockfd, const tls_init_config_t *cfg) { int status; tls_session_t *s; tls_d("Session init"); ASSERT(h != NULL); ASSERT(sockfd >= 0); ASSERT(cfg != NULL); s = os_mem_alloc(sizeof(tls_session_t)); if (!s) { tls_e("No memory for tls session"); return -WM_E_NOMEM; } memset(s, 0x00, sizeof(tls_session_t)); if (cfg->flags & TLS_SERVER_MODE) status = _tls_session_init_server(s, cfg); else status = _tls_session_init_client(s, sockfd, cfg); if (status != WM_SUCCESS) { os_mem_free(s); return status; } *h = (tls_handle_t) s; return WM_SUCCESS; }
int tls_derive_key(tls_session_t *s, size_t len) { struct tls_keys keys; unsigned char *rnd, *out; if (SSL_get_keys(s->ssl, &keys.master_key, &keys.master_key_len, &keys.server_random, &keys.server_random_len, &keys.client_random, &keys.client_random_len) == SSL_SUCCESS) { out = os_mem_alloc(len); if (out == NULL) { tls_e("No memory for tls_derive_key"); goto fail; } if (keys.master_key == NULL || keys.server_random ==NULL || keys.client_random == NULL) goto fail; rnd = os_mem_alloc(keys.client_random_len + keys.server_random_len); if (rnd == NULL) { tls_e("No memory for rnd:: %d", keys.client_random_len + keys.server_random_len); goto fail; } memcpy(rnd, keys.client_random, keys.client_random_len); memcpy(rnd + keys.client_random_len, keys.server_random, keys.server_random_len); mrvl_tls_prf(keys.master_key, keys.master_key_len, "client EAP encryption", rnd, keys.client_random_len + keys.server_random_len, out, len); memcpy(s->key_data, out, TLS_KEY_LEN); os_mem_free(rnd); os_mem_free(out); return WM_SUCCESS; } fail: tls_e("EAP-TLS: Failed to derive key"); return -WM_FAIL; }
int ssp_drv_close(mdev_t *dev) { sspdev_data_t *ssp_data_p; ssp_data_p = (sspdev_data_t *) dev->private_data; os_mem_free(ssp_data_p->rx_ringbuf.buf_p); SSP_Disable(dev->port_id); return os_mutex_put(&ssp_mutex[dev->port_id]); }
/* * Function used to deallocate the used rcb. */ void pqisrc_free_rcb(pqisrc_softstate_t *softs, int req_count) { uint32_t num_req; size_t size; int i; DBG_FUNC("IN\n"); num_req = softs->max_outstanding_io + 1; size = num_req * sizeof(rcb_t); for (i = 1; i < req_count; i++) os_dma_mem_free(softs, &softs->sg_dma_desc[i]); os_mem_free(softs, (void *)softs->rcb, size); softs->rcb = NULL; DBG_FUNC("OUT\n"); }
/*---------------------------------------------------------------------*/ __task void task3(void){ void *pointer; pointer = os_mem_alloc(box_mem); if (pointer == NULL) printf("Not enough memory\n"); else printf("malloc'd(): %d \n", pointer); os_dly_wait(50); if(os_mem_free(box_mem, pointer) == OS_R_OK){ printf("dealloc'd(): OS_R_OK \n"); }else{ printf("dealloc'd(): OS_R_NOK \n"); } os_dly_wait(50); os_tsk_delete_self(); }
/* * Write all data in the adapter's battery-backed cache to * storage. */ int pqisrc_flush_cache( pqisrc_softstate_t *softs, enum pqisrc_flush_cache_event_type event_type) { int rval = PQI_STATUS_SUCCESS; pqisrc_raid_req_t request; pqisrc_bmic_flush_cache_t *flush_buff = NULL; DBG_FUNC("IN\n"); if (pqisrc_ctrl_offline(softs)) return PQI_STATUS_FAILURE; flush_buff = os_mem_alloc(softs, sizeof(pqisrc_bmic_flush_cache_t)); if (!flush_buff) { DBG_ERR("Failed to allocate memory for flush cache params\n"); rval = PQI_STATUS_FAILURE; return rval; } flush_buff->halt_event = event_type; memset(&request, 0, sizeof(request)); rval = pqisrc_build_send_raid_request(softs, &request, flush_buff, sizeof(*flush_buff), SA_CACHE_FLUSH, 0, (uint8_t *)RAID_CTLR_LUNID, NULL); if (rval) { DBG_ERR("error in build send raid req ret=%d\n", rval); } if (flush_buff) os_mem_free(softs, (void *)flush_buff, sizeof(pqisrc_bmic_flush_cache_t)); DBG_FUNC("OUT\n"); return rval; }
void sem_debug_delete(const xSemaphoreHandle handle) { int temp, i; if (sem_mutex) { temp = os_mutex_get(&sem_mutex, OS_WAIT_FOREVER); if (temp == -WM_FAIL) { wmprintf("[sem-dbg] Failed to get sem-mutex\r\n"); return; } } for (i = 0; i < MAX_SEM_INFO_BUF; i++) { if (semdbg[i].x_queue == handle) { semdbg[i].x_queue = 0; os_mem_free(semdbg[i].q_name); semdbg[i].q_name = NULL; semcnt--; break; } } if (sem_mutex) os_mutex_put(&sem_mutex); return; }
/* This task configures Evrythng client and connects to the Evrythng cloud */ static void evrythng_task() { psm_handle_t handle; int rc; if ((rc = psm_open(&handle, "evrythng")) != 0) { wmprintf("psm_open failed with: %d (Is the module name registered?)\n\r", rc); goto exit; } char api_key[128]; if (psm_get(&handle, "api_key", api_key, 128) == 0) { wmprintf("api_key: %s\n\r", api_key); } else { wmprintf("api_key doesn't exist\n\r"); goto exit; } char thng_id_buf[64]; if (psm_get(&handle, "thng_id", thng_id_buf, 64) == 0) { if (thng_id != NULL) { os_mem_free(thng_id); } thng_id = (char*)os_mem_alloc((strlen(thng_id_buf)+1)*sizeof(char)); strcpy(thng_id, thng_id_buf); wmprintf("thng_id: %s\n\r", thng_id); } else { wmprintf("thng_id doesn't exist\n\r"); goto exit; } char url_buf[64]; if (psm_get(&handle, "url", url_buf, 64) == 0) { wmprintf("Evrythng URL: %s\n\r", url_buf); } else { wmprintf("Evrythng URL doesn't exist\n\r"); goto exit; } psm_close(&handle); EvrythngInitHandle(&evt_handle); EvrythngSetUrl(evt_handle, url_buf); EvrythngSetKey(evt_handle, api_key); EvrythngSetLogCallback(evt_handle, log_callback); EvrythngSetConnectionCallbacks(evt_handle, on_connection_lost, on_connection_restored); while (EvrythngConnect(evt_handle) != EVRYTHNG_SUCCESS) { wmprintf("Retry\n\r"); os_thread_sleep(os_msec_to_ticks(5000)); } wmprintf("Connected\n\r"); os_semaphore_create_counting(&button1_sem, "button1_sem", 1000, 0); os_semaphore_create_counting(&button2_sem, "button1_sem", 1000, 0); EvrythngSubThngAction(evt_handle, thng_id, "_led1", 0, action_led_callback); EvrythngSubThngAction(evt_handle, thng_id, "_led2", 0, action_led_callback); os_thread_create(&button1_thread, "button1_task", button_task, (void*)button_1, &button_stack, OS_PRIO_3); os_thread_create(&button2_thread, "button2_task", button_task, (void*)button_2, &button_stack, OS_PRIO_3); exit: os_thread_self_complete(0); }
/* * Request the adapter to get PQI capabilities supported. */ static int pqisrc_report_pqi_capability(pqisrc_softstate_t *softs) { int ret = PQI_STATUS_SUCCESS; DBG_FUNC("IN\n"); gen_adm_req_iu_t admin_req; gen_adm_resp_iu_t admin_resp; dma_mem_t pqi_cap_dma_buf; pqi_dev_cap_t *capability = NULL; pqi_iu_layer_desc_t *iu_layer_desc = NULL; /* Allocate Non DMA memory */ capability = os_mem_alloc(softs, sizeof(*capability)); if (!capability) { DBG_ERR("Failed to allocate memory for capability\n"); ret = PQI_STATUS_FAILURE; goto err_out; } memset(&admin_req, 0, sizeof(admin_req)); memset(&admin_resp, 0, sizeof(admin_resp)); memset(&pqi_cap_dma_buf, 0, sizeof(struct dma_mem)); pqi_cap_dma_buf.tag = "pqi_cap_buf"; pqi_cap_dma_buf.size = REPORT_PQI_DEV_CAP_DATA_BUF_SIZE; pqi_cap_dma_buf.align = PQISRC_DEFAULT_DMA_ALIGN; ret = os_dma_mem_alloc(softs, &pqi_cap_dma_buf); if (ret) { DBG_ERR("Failed to allocate capability DMA buffer : %d\n", ret); goto err_dma_alloc; } admin_req.fn_code = PQI_FUNCTION_REPORT_DEV_CAP; admin_req.req_type.general_func.buf_size = pqi_cap_dma_buf.size; admin_req.req_type.general_func.sg_desc.length = pqi_cap_dma_buf.size; admin_req.req_type.general_func.sg_desc.addr = pqi_cap_dma_buf.dma_addr; admin_req.req_type.general_func.sg_desc.type = SGL_DESCRIPTOR_CODE_DATA_BLOCK; ret = pqisrc_submit_admin_req(softs, &admin_req, &admin_resp); if( PQI_STATUS_SUCCESS == ret) { memcpy(capability, pqi_cap_dma_buf.virt_addr, pqi_cap_dma_buf.size); } else { DBG_ERR("Failed to send admin req report pqi device capability\n"); goto err_admin_req; } softs->pqi_dev_cap.max_iqs = capability->max_iqs; softs->pqi_dev_cap.max_iq_elements = capability->max_iq_elements; softs->pqi_dev_cap.max_iq_elem_len = capability->max_iq_elem_len; softs->pqi_dev_cap.min_iq_elem_len = capability->min_iq_elem_len; softs->pqi_dev_cap.max_oqs = capability->max_oqs; softs->pqi_dev_cap.max_oq_elements = capability->max_oq_elements; softs->pqi_dev_cap.max_oq_elem_len = capability->max_oq_elem_len; softs->pqi_dev_cap.intr_coales_time_granularity = capability->intr_coales_time_granularity; iu_layer_desc = &capability->iu_layer_desc[PQI_PROTOCOL_SOP]; softs->max_ib_iu_length_per_fw = iu_layer_desc->max_ib_iu_len; softs->ib_spanning_supported = iu_layer_desc->ib_spanning_supported; softs->ob_spanning_supported = iu_layer_desc->ob_spanning_supported; DBG_INIT("softs->pqi_dev_cap.max_iqs: %d\n", softs->pqi_dev_cap.max_iqs); DBG_INIT("softs->pqi_dev_cap.max_iq_elements: %d\n", softs->pqi_dev_cap.max_iq_elements); DBG_INIT("softs->pqi_dev_cap.max_iq_elem_len: %d\n", softs->pqi_dev_cap.max_iq_elem_len); DBG_INIT("softs->pqi_dev_cap.min_iq_elem_len: %d\n", softs->pqi_dev_cap.min_iq_elem_len); DBG_INIT("softs->pqi_dev_cap.max_oqs: %d\n", softs->pqi_dev_cap.max_oqs); DBG_INIT("softs->pqi_dev_cap.max_oq_elements: %d\n", softs->pqi_dev_cap.max_oq_elements); DBG_INIT("softs->pqi_dev_cap.max_oq_elem_len: %d\n", softs->pqi_dev_cap.max_oq_elem_len); DBG_INIT("softs->pqi_dev_cap.intr_coales_time_granularity: %d\n", softs->pqi_dev_cap.intr_coales_time_granularity); DBG_INIT("softs->max_ib_iu_length_per_fw: %d\n", softs->max_ib_iu_length_per_fw); DBG_INIT("softs->ib_spanning_supported: %d\n", softs->ib_spanning_supported); DBG_INIT("softs->ob_spanning_supported: %d\n", softs->ob_spanning_supported); os_mem_free(softs, (void *)capability, REPORT_PQI_DEV_CAP_DATA_BUF_SIZE); os_dma_mem_free(softs, &pqi_cap_dma_buf); DBG_FUNC("OUT\n"); return ret; err_admin_req: os_dma_mem_free(softs, &pqi_cap_dma_buf); err_dma_alloc: if (capability) os_mem_free(softs, (void *)capability, REPORT_PQI_DEV_CAP_DATA_BUF_SIZE); err_out: DBG_FUNC("failed OUT\n"); return PQI_STATUS_FAILURE; }
mlan_status wrapper_moal_mfree(IN t_void *pmoal_handle, IN t_u8 *pbuf) { w_mem_d("[mlan] Free: A: %p", pbuf); os_mem_free(pbuf); return MLAN_STATUS_SUCCESS; }
void wifi_free_eventbuf(void *buffer) { w_mem_d("[evtbuf] Free: A: %p\n\r", buffer); os_mem_free(buffer); }
static void cyassl_mem_free(void *buffer) { os_mem_free(buffer); }
int httpd_handle_file(httpd_request_t *req_p, struct fs *fs) { const char *anchor = "/"; char tmp[HTTPD_MAX_URI_LENGTH+1]; const char *encoding = NULL; char *msg_in, *ptr, *type = NULL; int err, msg_in_len = HTTPD_MAX_MESSAGE - 1, conn = req_p->sock; int ret; msg_in = os_mem_alloc(HTTPD_MAX_MESSAGE + 2); if (!msg_in) { httpd_e("Failed to allocate memory for file handling"); /* Check what needs to be returned */ return -WM_FAIL; } memset(msg_in, 0, HTTPD_MAX_MESSAGE + 2); SYS_FILE_DECL; if (!fs) { /* The filesystem wasn't mounted properly */ httpd_send_hdr_from_str(conn, http_header_404, CONTENT_TYPE_PLAIN, encoding, NO_CACHE_HEADERS, UNUSED_PARAM); httpd_send_default_headers(conn, req_p->wsgi->hdr_fields); httpd_send_crlf(conn); httpd_send(conn, FILE_NOT_FOUND, sizeof(FILE_NOT_FOUND)); ret = WM_SUCCESS; goto out; } struct ftfs_super *f_super = fs_to_ftfs_sb(fs); /* Ensure that the anchor is the first part of the filename */ ptr = strstr(req_p->filename, anchor); if (ptr == NULL || ptr != req_p->filename) { httpd_d("No anchor in filename\r\n"); ret = httpd_send_error(conn, HTTP_500); goto out; } /* Zap the anchor from the filename */ ptr = req_p->filename + strlen(anchor); err = 0; /* anchors are only across directory boundaries */ if (*ptr != '/') req_p->filename[err++] = '/'; while (*ptr && (*ptr != '?')) { req_p->filename[err] = *ptr; ptr++; err++; } req_p->filename[err] = '\0'; /* "/" implies a request for index.html */ if (strncmp(req_p->filename, "/", 2) == 0) { strncpy(req_p->filename, http_index_html, sizeof(http_index_html)); } /* Find if .gz version exists for file, if it is then serve that */ type = strrchr(req_p->filename, ISO_period); if (type) { strncpy(tmp, req_p->filename, sizeof(tmp)); strncat(tmp, ".gz", 3); httpd_d("Look for gz file if it exists: %s\r\n", tmp); if (htsys_file_open(fs, tmp, sys_filep) == WM_SUCCESS) { /* Gzipped version exists, serve that */ httpd_d("Serve gzipped file\r\n"); strncpy(req_p->filename, tmp, HTTPD_MAX_URI_LENGTH + 1); encoding = ".gz"; htsys_close(fs, sys_filep); } } ret = httpd_parse_hdr_tags(req_p, conn, msg_in, msg_in_len); if (ret < 0) { httpd_d("Parsing headers failed \r\n"); ret = httpd_send_error(conn, HTTP_500); goto out; } /* It is not a WSGI, check to see if the file exists */ if (htsys_file_open(fs, req_p->filename, sys_filep) == -WM_FAIL) { httpd_w("file not found: %s\r\n", req_p->filename); ret = httpd_send_hdr_from_str(conn, http_header_404, type, encoding, NO_CACHE_HEADERS, UNUSED_PARAM); httpd_send_default_headers(conn, req_p->wsgi->hdr_fields); httpd_send_crlf(conn); if (ret != WM_SUCCESS) goto out; ret = htsys_file_open(fs, http_404_html, sys_filep); if (ret == WM_SUCCESS) { ret = httpd_send_file(fs, conn, sys_filep); goto out; } else httpd_w("No local 404 file. Sending empty 404" " response.\r\n"); } else { /* Ok, the file exists, is it a script html or just html */ g_wm_stats.wm_hd_file++; if (req_p->if_none_match && (f_super->fs_crc32 == req_p->etag_val)) { /* We do not need the file handle now */ htsys_close(fs, sys_filep); /* Send Not Modified header */ /* Send header prologue */ ret = httpd_send(conn, http_header_304_prologue, strlen(http_header_304_prologue)); if (ret != WM_SUCCESS) goto out; httpd_send_header(conn, "Server", "Marvell-WM"); httpd_send_header(conn, "Connection", "Close"); /* Send ETag */ int len; const char *h = httpd_get_etag_hdr(req_p->etag_val, &len); ret = httpd_send(conn, h, len); if (ret != WM_SUCCESS) goto out; /* Close the header */ ret = httpd_send_crlf(conn); goto out; } else { ret = httpd_send_hdr_from_str(conn, http_header_200, type, encoding, SEND_CACHE_HEADERS, f_super->fs_crc32); httpd_send_default_headers(conn, req_p->wsgi->hdr_fields); httpd_send_crlf(conn); if (ret != WM_SUCCESS) goto out; ptr = strchr(req_p->filename, ISO_period); if (ptr != NULL && strncmp(ptr, http_shtml, sizeof(http_shtml) - 1) == 0) { httpd_d("Handling script: %s", req_p->filename); ret = handle_script(fs, req_p, conn, sys_filep, msg_in); htsys_close(fs, sys_filep); if (ret != WM_SUCCESS) { httpd_d("Script failed\r\n"); goto out; } } else { ret = httpd_send_file(fs, conn, sys_filep); if (ret != WM_SUCCESS) goto out; } } } ret = httpd_send_last_chunk(conn); out: os_mem_free(msg_in); return ret; }
void wps_mem_free(void *buffer_ptr) { if (buffer_ptr) os_mem_free(buffer_ptr); }