Example #1
0
INT32 wmt_idc_msg_to_lte_handing(VOID)
{
	UINT32 readlen = 0;
	local_para_struct *p_lps = NULL;
	UINT8 *p_data = NULL;
	UINT8 opcode = 0;
	UINT16 msg_len = 0;
	UINT32 handle_len = 0;
#if	CFG_WMT_LTE_ENABLE_MSGID_MAPPING
	MTK_WCN_BOOL unknow_msgid = MTK_WCN_BOOL_FALSE;
#endif
	readlen = mtk_wcn_stp_receive_data(&gWmtIdcInfo.buffer[0], LTE_IDC_BUFFER_MAX_SIZE, COEX_TASK_INDX);
	if (readlen == 0) {
		osal_sleep_ms(5);
		readlen = mtk_wcn_stp_receive_data(&gWmtIdcInfo.buffer[0], LTE_IDC_BUFFER_MAX_SIZE, COEX_TASK_INDX);
	}

	if (readlen > 0) {
		WMT_DBG_FUNC("read data len from fw(%d)\n", readlen);
		wmt_idc_dump_debug_msg("WMT->LTE from STP buffer", &gWmtIdcInfo.buffer[0], readlen);
		p_data = &gWmtIdcInfo.buffer[0];

		while (handle_len < readlen) {
			p_data += 2;	/*omit direction & opcode 2 bytes */
			osal_memcpy(&msg_len, p_data, 2);
			msg_len -= 1;	/*flag byte */
			WMT_DBG_FUNC("current raw data len(%d) from connsys firmware\n", msg_len);

			p_data += 2;	/*length: 2 bytes */

			/*how to handle flag(msg type) need to Scott comment */
			/************************************************/

			if (*p_data == WMT_IDC_RX_OPCODE_DEBUG_MONITOR)
				/*do not need transfer to LTE */
			{
				p_data += 1;	/*flag : 1 byte */
				/*need to handle these debug message */
				wmt_idc_dump_debug_msg("WIFI DEBUG MONITOR", p_data, msg_len);
			} else
				/*need to transfer to LTE */
			{
				p_lps =
				    (local_para_struct *) osal_malloc(osal_sizeof(local_para_struct) +
								      osal_sizeof(UINT8) * msg_len);
				if (NULL == p_lps) {
					WMT_ERR_FUNC("allocate local_para_struct memory fail\n");
					return -1;
				}

				p_lps->msg_len = msg_len + osal_sizeof(local_para_struct);

				opcode = *p_data;
				WMT_DBG_FUNC("current opcode(%d) to LTE\n", opcode);

				p_data += 1;	/*flag : 1 byte */
				osal_memcpy(p_lps->data, p_data, msg_len);

				gWmtIdcInfo.iit.local_para_ptr = p_lps;

#if	CFG_WMT_LTE_ENABLE_MSGID_MAPPING
				switch (opcode) {
				case WMT_IDC_RX_OPCODE_BTWF_DEF_PARA:
					gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_OPER_DEFAULT_PARAM_IND;
					break;
				case WMT_IDC_RX_OPCODE_BTWF_CHAN_RAN:
					gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_OPER_FREQ_IND;
					break;
				case WMT_IDC_RX_OPCODE_LTE_FREQ_IDX_TABLE:
					gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_FREQ_IDX_TABLE_IND;
					break;
				case WMT_IDC_RX_OPCODE_BTWF_PROFILE_IND:
					gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_PROFILE_IND;
					break;
				case WMT_IDC_RX_OPCODE_UART_PIN_SEL:
					gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_PIN_TYPE_IND;
					break;
					/* case WMT_IDC_RX_OPCODE_TDM_REQ: */
					/* gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_OPER_FREQ_IND; */
					/* break; */
				default:
					unknow_msgid = MTK_WCN_BOOL_TRUE;
					WMT_ERR_FUNC("unknow opcode(%d) from connsys firmware\n", opcode);
					break;
				}
				if (MTK_WCN_BOOL_FALSE == unknow_msgid) {
					/*handling flag value in wmt cmd */
					mtk_conn_md_bridge_send_msg(&gWmtIdcInfo.iit);
				}
#else
				if (opcode >= LTE_MSG_ID_OFFSET) {
					gWmtIdcInfo.iit.msg_id = opcode + IPC_EL1_MSG_ID_BEGIN - LTE_MSG_ID_OFFSET + 1;
					/*handling flag value in wmt cmd */
					mtk_conn_md_bridge_send_msg(&gWmtIdcInfo.iit);
					WMT_INFO_FUNC("CONN->LTE: (0x%x->0x%x)\n", opcode, gWmtIdcInfo.iit.msg_id);
				} else {
					WMT_ERR_FUNC("opcode(%d)from connsys fw is out of range,drop it!\n", opcode);
				}
#endif
				osal_free(p_lps);
			}

			p_data += msg_len;	/*point to next package header */

			handle_len += (msg_len + 5);
		}

	} else {
		WMT_ERR_FUNC("there is no coex data in stp buffer\n");
	}

	osal_memset(&gWmtIdcInfo.buffer[0], 0, LTE_IDC_BUFFER_MAX_SIZE);

	return 0;
}
UINT32 wmt_idc_msg_to_lte_handing_for_test(UINT8 *p_buf,UINT32 len)
{
	UINT32 readlen = len;
	local_para_struct * p_lps = NULL;
	UINT8 *p_data = NULL;
	UINT8 opcode = 0;
	UINT16 msg_len = 0;
	UINT32 handle_len = 0;
	MTK_WCN_BOOL unknow_msgid = MTK_WCN_BOOL_FALSE;

	osal_memcpy(&gWmtIdcInfo.buffer[0],p_buf,len);

	if(readlen > 0)
	{
		WMT_DBG_FUNC("read data len from fw(%d)\n",readlen);
		p_data = &gWmtIdcInfo.buffer[0];
		
		while(handle_len < readlen)
		{
			p_data += 2;/*omit direction & opcode 2 bytes*/
			osal_memcpy(&msg_len,p_data,2);
			msg_len -= 1;/*flag byte*/
			WMT_DBG_FUNC("current raw data len(%d) from connsys firmware\n",msg_len);

			p_data += 2;/*length: 2 bytes*/

			/*how to handle flag(msg type) need to Scott comment*/
			/************************************************/

			if(*p_data == WMT_IDC_RX_OPCODE_DEBUG_MONITOR)
			/*do not need transfer to LTE*/
			{
				p_data += 1;/*flag : 1 byte*/
				/*need to handle these debug message*/
				wmt_idc_dump_debug_msg("WIFI DEBUG MONITOR",p_data,msg_len);
			}
			else
			/*need to transfer to LTE*/
			{
				p_lps = (local_para_struct *)osal_malloc(osal_sizeof(local_para_struct) + osal_sizeof(UINT8) * msg_len);
				if(NULL == p_lps)
				{
					WMT_ERR_FUNC("allocate local_para_struct memory fail\n");
					return -1;
				}
			
				p_lps->msg_len = msg_len + osal_sizeof(local_para_struct);

				opcode = *p_data;
				WMT_DBG_FUNC("current opcode(%d) to LTE\n",opcode);
				
				p_data += 1;/*flag : 1 byte*/
				osal_memcpy(p_lps->data,p_data,msg_len);

				gWmtIdcInfo.iit.local_para_ptr = p_lps;

				switch(opcode)
				{
					case WMT_IDC_RX_OPCODE_BTWF_DEF_PARA:
						gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_OPER_DEFAULT_PARAM_IND;
						break;
					case WMT_IDC_RX_OPCODE_BTWF_CHAN_RAN:
						gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_OPER_FREQ_IND;
						break;
					//case WMT_IDC_RX_OPCODE_TDM_REQ:
					//	gWmtIdcInfo.iit.msg_id = IPC_MSG_ID_EL1_WIFIBT_OPER_FREQ_IND;
					//	break;
					default:
						unknow_msgid = MTK_WCN_BOOL_TRUE;
						WMT_ERR_FUNC("unknow opcode(%d) from connsys firmware\n",opcode);
						break;
				}
				if(MTK_WCN_BOOL_FALSE == unknow_msgid){
					/*handling flag value in wmt cmd*/
					mtk_conn_md_bridge_send_msg(&gWmtIdcInfo.iit);
				}
				osal_free(p_lps);
			}

			p_data += msg_len; /*point to next package header*/

			handle_len += (msg_len + 5);
		}
		
	}else
	{
		WMT_ERR_FUNC("there is no coex data in stp buffer\n");
	}

	osal_memset(&gWmtIdcInfo.buffer[0],0,LTE_IDC_BUFFER_MAX_SIZE);	

	return handle_len;
}
/* wcn_compressor_init - create a compressor and do init
 * @ name - compressor's name
 * @ L1_buf_sz - L1 buffer size
 * @ L2_buf_sz - L2 buffer size
 *
 * Retunr object's pointer if success, else NULL
 */
P_WCN_COMPRESSOR_T wcn_compressor_init(PUINT8 name, INT32 L1_buf_sz, INT32 L2_buf_sz)
{
    z_stream *pstream = NULL;
    P_WCN_COMPRESSOR_T compress = NULL;

    compress = (P_WCN_COMPRESSOR_T)osal_malloc(sizeof(WCN_COMPRESSOR_T));
    if (!compress) {
        STP_DBG_ERR_FUNC("alloc compressor failed!\n");
        goto fail;
    }

    osal_memset(compress, 0, sizeof(WCN_COMPRESSOR_T));
    osal_memcpy(compress->name, name, STP_OJB_NAME_SZ);

    compress->f_compress_en = 0;
    compress->compress_type = GZIP;

    if (compress->compress_type == GZIP) {
        compress->worker = osal_malloc(sizeof(z_stream));
        if (!compress->worker) {
            STP_DBG_ERR_FUNC("alloc stream failed!\n");
            goto fail;
        }
        pstream = (z_stream*)compress->worker;

        pstream->workspace = osal_malloc(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL));
        if (!pstream->workspace) {
            STP_DBG_ERR_FUNC("alloc workspace failed!\n");
            goto fail;
        }
        zlib_deflateInit2(pstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS,
                          DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
    }

    compress->handler = wcn_gzip_compressor;
    compress->L1_buf_sz = L1_buf_sz;
    compress->L2_buf_sz = L2_buf_sz;
    compress->L1_pos = 0;
    compress->L2_pos = 0;
    compress->uncomp_size = 0;
    compress->crc32 = 0xffffffffUL;

    compress->L1_buf = osal_malloc(compress->L1_buf_sz);
    if (!compress->L1_buf) {
        STP_DBG_ERR_FUNC("alloc %d bytes for L1 buf failed!\n", compress->L1_buf_sz);
        goto fail;
    }

    compress->L2_buf = osal_malloc(compress->L2_buf_sz);
    if (!compress->L2_buf) {
        STP_DBG_ERR_FUNC("alloc %d bytes for L2 buf failed!\n", compress->L2_buf_sz);
        goto fail;
    }

    STP_DBG_INFO_FUNC("create compressor OK! L1 %d bytes, L2 %d bytes\n", L1_buf_sz, L2_buf_sz);
    return compress;

fail:
    if (compress) {
        if (compress->L2_buf) {
            osal_free(compress->L2_buf);
            compress->L2_buf = NULL;
        }

        if (compress->L1_buf) {
            osal_free(compress->L1_buf);
            compress->L1_buf = NULL;
        }

        if (compress->worker) {
            pstream = (z_stream*)compress->worker;
            if ((compress->compress_type == GZIP) && pstream->workspace) {
                zlib_deflateEnd(pstream);
                osal_free(pstream->workspace);
            }
            osal_free(compress->worker);
            compress->worker = NULL;
        }

        if (compress->worker) {
            osal_free(compress->worker);
            compress->worker = NULL;
        }

        osal_free(compress);
        compress = NULL;
    }

    STP_DBG_ERR_FUNC("init failed!\n");

    return NULL;
}
Example #4
0
/*!
 * \brief Get header id from the request parameter and take appropriate
 * action based on the ids as an HTTP Range Response.
 *
 * \return
 * \li \c HTTP_BAD_REQUEST
 * \li \c HTTP_INTERNAL_SERVER_ERROR
 * \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
 * \li \c HTTP_OK
 */
static int CheckOtherHTTPHeaders(
	/*! [in] HTTP Request message. */
	http_message_t *Req,
	/*! [out] Send Instruction object to data for the response. */
	struct SendInstruction *RespInstr,
	/*! Size of the file containing the request document. */
	off_t FileSize)
{
	http_header_t *header;
	ListNode *node;
	/*NNS: dlist_node* node; */
	int index, RetCode = HTTP_OK;
	char *TmpBuf;
	size_t TmpBufSize = LINE_SIZE;

	TmpBuf = (char *)osal_malloc(TmpBufSize);
	if (!TmpBuf)
		return HTTP_INTERNAL_SERVER_ERROR;
	node = ListHead(&Req->headers);
	while (node != NULL) {
		header = (http_header_t *) node->item;
		/* find header type. */
		index = map_str_to_int((const char *)header->name.buf,
				header->name.length, Http_Header_Names,
				NUM_HTTP_HEADER_NAMES, FALSE);
		if (header->value.length >= TmpBufSize) {
			osal_free(TmpBuf);
			TmpBufSize = header->value.length + 1;
			TmpBuf = (char *)osal_malloc(TmpBufSize);
			if (!TmpBuf)
				return HTTP_INTERNAL_SERVER_ERROR;
		}
		memcpy(TmpBuf, header->value.buf, header->value.length);
		TmpBuf[header->value.length] = '\0';
		if (index >= 0) {
			switch (Http_Header_Names[index].id) {
			case HDR_TE: {
				/* Request */
				RespInstr->IsChunkActive = 1;

				if (strlen(TmpBuf) > strlen("gzip")) {
					/* means client will accept trailer. */
					if (StrStr(TmpBuf, "trailers") != NULL) {
						RespInstr->IsTrailers = 1;
					}
				}
				break;
			}
			case HDR_CONTENT_LENGTH:
				RespInstr->RecvWriteSize = atoi(TmpBuf);
				break;
			case HDR_RANGE:
				if (FileSize == UPNP_UNTIL_CLOSE) {
					/* not a real file, nothing to do */
					break;
				}
				RetCode = CreateHTTPRangeResponseHeader(TmpBuf,
					FileSize, RespInstr);
				if (RetCode != HTTP_OK) {
					osal_free(TmpBuf);
					return RetCode;
				}
				break;
			case HDR_ACCEPT_LANGUAGE:
				if (header->value.length + 1 > sizeof(RespInstr->AcceptLanguageHeader)) {
					size_t length = sizeof(RespInstr->AcceptLanguageHeader) - 1;
					memcpy(RespInstr->AcceptLanguageHeader, TmpBuf, length);
					RespInstr->AcceptLanguageHeader[length] = '\0';
				} else {
					memcpy(RespInstr->AcceptLanguageHeader, TmpBuf,
						header->value.length + 1);
				}
				break;
			default:
				// UpnpPrintf(UPNP_WARN, HTTP, __FILE__, __LINE__, "HTTP: REQUEST not SUPPORT %s\r\n", header->name.buf);
				/*
				   TODO
				 */
				/*
				   header.value is the value.
				 */
				/*
				   case HDR_CONTENT_TYPE: return 1;
				   case HDR_CONTENT_LANGUAGE:return 1;
				   case HDR_LOCATION: return 1;
				   case HDR_CONTENT_LOCATION:return 1;
				   case HDR_ACCEPT: return 1;
				   case HDR_ACCEPT_CHARSET: return 1;
				   case HDR_USER_AGENT: return 1;
				 */

				/*Header check for encoding */
				/*
				   case HDR_ACCEPT_RANGE:
				   case HDR_CONTENT_RANGE:
				   case HDR_IF_RANGE:
				 */

				/*Header check for encoding */
				/*
				   case HDR_ACCEPT_ENCODING:
				   if(StrStr(TmpBuf, "identity"))
				   {
				   break;
				   }
				   else return -1;
				   case HDR_CONTENT_ENCODING:
				   case HDR_TRANSFER_ENCODING:
				 */
				break;
			}
		}
		node = ListNext(&Req->headers, node);
	}
	osal_free(TmpBuf);

	return RetCode;
}
Example #5
0
static INT32 wmt_conf_parse(P_DEV_WMT pWmtDev, const PINT8 pInBuf, UINT32 size)
{
	PINT8 pch;
	PINT8 pBuf;
	PINT8 pLine;
	PINT8 pKey;
	PINT8 pVal;
	PINT8 pPos;
	INT32 ret = 0;
	INT32 i = 0;
	PINT8 pa = NULL;

	pBuf = osal_malloc(size);
	if (!pBuf)
		return -1;

	osal_memcpy(pBuf, pInBuf, size);
	pBuf[size] = '\0';

	pch = pBuf;
	/* pch is to be updated by strsep(). Keep pBuf unchanged!! */

#if 0
	{
		PINT8 buf_ptr = pBuf;
		INT32 k = 0;
		WMT_INFO_FUNC("%s len=%d", "wmcfg.content:", size);
		for (k = 0; k < size; k++) {
			/* if(k%16 == 0)  WMT_INFO_FUNC("\n"); */
			WMT_INFO_FUNC("%c", buf_ptr[k]);
		}
		WMT_INFO_FUNC("--end\n");
	}
#endif

	while ((pLine = osal_strsep(&pch, "\r\n")) != NULL) {
		/* pch is updated to the end of pLine by strsep() and updated to '\0' */
		/*WMT_INFO_FUNC("strsep offset(%d), char(%d, '%c' )\n", pLine-pBuf, *pLine, *pLine); */
		/* parse each line */

		/* WMT_INFO_FUNC("==> Line = (%s)\n", pLine); */

		if (!*pLine)
			continue;

		pVal = osal_strchr(pLine, '=');
		if (!pVal) {
			WMT_WARN_FUNC("mal-format cfg string(%s)\n", pLine);
			continue;
		}

		/* |<-pLine->|'='<-pVal->|'\n' ('\0')|  */
		*pVal = '\0';	/* replace '=' with '\0' to get key */
		/* |<-pKey->|'\0'|<-pVal->|'\n' ('\0')|  */
		pKey = pLine;

		if ((pVal - pBuf) < size)
			pVal++;

		/*key handling */
		pPos = pKey;
		/*skip space characeter */
		while (((*pPos) == ' ') || ((*pPos) == '\t') || ((*pPos) == '\n')) {
			if ((pPos - pBuf) >= size)
				break;
			pPos++;
		}
		/*key head */
		pKey = pPos;
		while (((*pPos) != ' ') && ((*pPos) != '\t') && ((*pPos) != '\0') && ((*pPos) != '\n')) {
			if ((pPos - pBuf) >= size)
				break;
			pPos++;
		}
		/*key tail */
		(*pPos) = '\0';

		/*value handling */
		pPos = pVal;
		/*skip space characeter */
		while (((*pPos) == ' ') || ((*pPos) == '\t') || ((*pPos) == '\n')) {
			if ((pPos - pBuf) >= size)
				break;
			pPos++;
		}
		/*value head */
		pVal = pPos;
		while (((*pPos) != ' ') && ((*pPos) != '\t') && ((*pPos) != '\0') && ((*pPos) != '\n')) {
			if ((pPos - pBuf) >= size)
				break;
			pPos++;
		}
		/*value tail */
		(*pPos) = '\0';

		/* WMT_DBG_FUNC("parse (key: #%s#, value: #%s#)\n", pKey, pVal); */
		ret = wmt_conf_parse_pair(pWmtDev, pKey, pVal);
		WMT_WARN_FUNC("parse (%s, %s, %d)\n", pKey, pVal, ret);
		if (ret)
			WMT_WARN_FUNC("parse fail (%s, %s, %d)\n", pKey, pVal, ret);
	}

	for (i = 0; i < NUM_WMTCFG_FIELDS; i++) {
		const struct parse_data *field = &wmtcfg_fields[i];
		pa = field->writer(pWmtDev, field);
		if (pa) {
			WMT_DBG_FUNC("#%d(%s)=>%s\n", i, field->name, pa);
			osal_free(pa);
		} else {
			WMT_ERR_FUNC("failed to parse '%s'.\n", field->name);
		}
	}
	osal_free(pBuf);
	return 0;
}
Example #6
0
/*!
 * \brief Fills in the Offset, read size and contents to send out as an HTTP
 * Range Response.
 *
 * \return
 * \li \c HTTP_BAD_REQUEST
 * \li \c HTTP_INTERNAL_SERVER_ERROR
 * \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
 * \li \c HTTP_OK
 */
static int CreateHTTPRangeResponseHeader(
	/*! String containing the range. */
	char *ByteRangeSpecifier,
	/*! Length of the file. */
	off_t FileLength,
	/*! [out] SendInstruction object where the range operations will be stored. */
	struct SendInstruction *Instr)
{
	unsigned long FirstByte, LastByte;
	char *RangeInput;
	char *Ptr;
	int rc = 0;

	Instr->IsRangeActive = 1;
	Instr->ReadSendSize = FileLength;
	if (!ByteRangeSpecifier)
		return HTTP_BAD_REQUEST;
	RangeInput = osal_malloc(strlen(ByteRangeSpecifier) + 1);
	if (!RangeInput)
		return HTTP_INTERNAL_SERVER_ERROR;
	strcpy(RangeInput, ByteRangeSpecifier);
	/* CONTENT-RANGE: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
	if (StrStr(RangeInput, "bytes") == NULL ||
	    (Ptr = StrStr(RangeInput, "=")) == NULL) {
		osal_free(RangeInput);
		Instr->IsRangeActive = 0;
		return HTTP_BAD_REQUEST;
	}
	/* Jump = */
	Ptr = Ptr + 1;
	/*
	 * TODO: FileLength is an unsigned long, support ~4G (except -4(UPNP_UNTIL_CLOSE))
	if ((int)FileLength < 0) {
		osal_free(RangeInput);
		printc("BAD REQUEST: %s %d\r\n", __func__, __LINE__);
		return HTTP_REQUEST_RANGE_NOT_SATISFIABLE;
	}
	*/
	if (GetNextRange(&Ptr, (off_t*)&FirstByte, (off_t*)&LastByte) != -1) {
		if (FileLength < FirstByte) {
			osal_free(RangeInput);
			return HTTP_REQUEST_RANGE_NOT_SATISFIABLE;
		}
		if (LastByte >= FirstByte) {
			if (LastByte >= FileLength)
				LastByte = FileLength - 1;
			Instr->RangeOffset = FirstByte;
			Instr->ReadSendSize = LastByte - FirstByte + 1;
			/* Data between two range. */
			rc = snprintf(Instr->RangeHeader,
				sizeof(Instr->RangeHeader),
				"CONTENT-RANGE: bytes %" PRId64
				"-%" PRId64 "/%" PRId64 "\r\n",
				(int64_t)FirstByte,
				(int64_t)LastByte,
				(int64_t)FileLength);
			if (rc < 0 || (unsigned int) rc >= sizeof(Instr->RangeHeader)) {
				osal_free(RangeInput);
				return HTTP_INTERNAL_SERVER_ERROR;
			}
		} else {
			osal_free(RangeInput);
			return HTTP_REQUEST_RANGE_NOT_SATISFIABLE;
		}
	} else {
		osal_free(RangeInput);
		return HTTP_REQUEST_RANGE_NOT_SATISFIABLE;
	}

	osal_free(RangeInput);
	return HTTP_OK;
}
Example #7
0
/*!
 * \brief Receives the HTTP post message.
 *
 * \return
 * \li \c HTTP_INTERNAL_SERVER_ERROR
 * \li \c HTTP_UNAUTHORIZED
 * \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
 * \li \c HTTP_OK
 */
static int http_RecvPostMessage(
	/*! HTTP Parser object. */
	http_parser_t *parser,
	/*! [in] Socket Information object. */
	SOCKINFO *info,
	/*! File where received data is copied to. */
	char *filename,
	/*! Send Instruction object which gives information whether the file
	 * is a virtual file or not. */
	struct SendInstruction *Instr)
{
	char *Buf = NULL;   // char Buf[1024];
	int Timeout = 0;
	OSAL_FILE *Fp;
	//parse_status_t status = PARSE_OK;
	int ok_on_close = FALSE;
	int num_read = 0;
	int ret_code = HTTP_OK;
	long	wrcb;

	if (Instr && Instr->IsVirtualFile) {
		struct File_Info finfo;
		/*
		 * give parser into extra_head of get_info to parsing continually
		 */
		if (parser->scanner.msg->length - parser->scanner.cursor < 512) {
			// the buffer run out, and all of header may not receive yet.
			// try to read again.
			char	*buffer;
			buffer = (char*)osal_malloc(2048);
			if (!buffer) {printc(BG_RED("%s %d:ERROR\n"), __func__, __LINE__);return 0;}
			num_read = sock_read(info, buffer, 2048, &Timeout);
			if (num_read > 0) {
				membuffer_append(&parser->msg.msg, buffer, (size_t)num_read);
			}
			osal_free(buffer);
		}
		virtualDirCallback.get_info(filename, &parser->msg, (char**)parser, &finfo, NULL); // to tell our HTTP Request Message
		Fp = (virtualDirCallback.open) (filename, UPNP_WRITE);
		if (Fp == NULL)
			return HTTP_INTERNAL_SERVER_ERROR;
	} else {
		Fp = osal_fopen(filename, "wb");
		if (Fp == NULL)
			return HTTP_UNAUTHORIZED;
		parser->position = POS_ENTITY;
	}
	wrcb = 0;
	/* read more if necessary entity */
	if (Instr && Instr->IsVirtualFile) {
		// get current total written size
		wrcb = virtualDirCallback.write(Fp, NULL, 0);
		// the wrcb is total size of data that had been written after the file opend
		// Instr->RecvWriteSize is Content-Length
		if (wrcb == Instr->RecvWriteSize) {
			// got all of data
			ret_code = HTTP_OK;
			parser->position = POS_COMPLETE;
		}
	}
	Buf = osal_malloc(1024);
	while (wrcb < Instr->RecvWriteSize) {
			num_read = sock_read(info, Buf, 1024, &Timeout);
		if (num_read > 0) {
			if (Instr && Instr->IsVirtualFile) {
				// 
				wrcb = virtualDirCallback.write(Fp, Buf, num_read);
				if (wrcb < 0) {
					ret_code = HTTP_INTERNAL_SERVER_ERROR;
					goto ExitFunction;
				}
				// the wrcb is total size of data that had been written after the file opend
				// Instr->RecvWriteSize is Content-Length
				if (wrcb == Instr->RecvWriteSize) {
					// got all of data
					ret_code = HTTP_OK;
					parser->position = POS_COMPLETE;
					}
				} else {
					size_t n = osal_fwrite(Buf, 1, num_read, Fp);
				if (n != num_read) {
					ret_code = HTTP_INTERNAL_SERVER_ERROR;
					goto ExitFunction;
				}
				}
			} else if (num_read == 0) {
				if (ok_on_close) {
					UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
						"<<< (RECVD) <<<\n%s\n-----------------\n",
						parser->msg.msg.buf);
					print_http_headers(&parser->msg);
					parser->position = POS_COMPLETE;
				} else {
					/* partial msg or response */
					parser->http_error_code = HTTP_BAD_REQUEST;
					ret_code = HTTP_BAD_REQUEST;
					goto ExitFunction;
				}
			} else {
				//ret_code = num_read;
			printc("TIME OUT total read %d\n", wrcb);
			ret_code = HTTP_PARTIAL_CONTENT;
			goto ExitFunction;
		}
	}
ExitFunction:
	if (Instr && Instr->IsVirtualFile) {
		virtualDirCallback.close(Fp);
	} else {
		osal_fclose(Fp);
	}

	if (Buf) osal_free(Buf);
	return ret_code;
}
Example #8
0
/*!
 * \brief Processes the request and returns the result in the output parameters.
 *
 * \return
 * \li \c HTTP_BAD_REQUEST
 * \li \c HTTP_INTERNAL_SERVER_ERROR
 * \li \c HTTP_REQUEST_RANGE_NOT_SATISFIABLE
 * \li \c HTTP_OK
 */
static int process_request(
	/*! [in] HTTP Request message. */
	http_message_t *req,
	/*! [out] Type of response. */
	enum resp_type *rtype,
	/*! [out] Headers. */
	membuffer *headers,
	/*! [out] Get filename from request document. */
	membuffer *filename,
	/*! [out] Xml alias document from the request document. */
	struct xml_alias_t *alias,
	/*! [out] Send Instruction object where the response is set up. */
	struct SendInstruction *RespInstr)
{
	int code;
	int err_code;

	char *request_doc;
	struct File_Info finfo;
	int using_alias;
	int using_virtual_dir;
	uri_type *url;
	const char *temp_str;
	int resp_major;
	int resp_minor;
	int alias_grabbed;
	size_t dummy;
	char *extra_headers = NULL;
	int extra_func; //chrison

	print_http_headers(req);
	url = &req->uri;
	assert(req->method == HTTPMETHOD_GET ||
	       req->method == HTTPMETHOD_HEAD ||
	       req->method == HTTPMETHOD_POST ||
	       req->method == HTTPMETHOD_SIMPLEGET);
	/* init */
	memset(&finfo, 0, sizeof(finfo));
	request_doc = NULL;
	finfo.content_type = NULL;
	alias_grabbed = FALSE;
	err_code = HTTP_INTERNAL_SERVER_ERROR;	/* default error */
	using_virtual_dir = FALSE;
	using_alias = FALSE;

	http_CalcResponseVersion(req->major_version, req->minor_version,
				 &resp_major, &resp_minor);
	/* */
	/* remove dots */
	/* */
	request_doc = osal_malloc(url->pathquery.size + 1);
	if (request_doc == NULL) {
		goto error_handler;	/* out of mem */
	}
	memcpy(request_doc, url->pathquery.buff, url->pathquery.size);
	request_doc[url->pathquery.size] = '\0';
	dummy = url->pathquery.size;
	remove_escaped_chars(request_doc, &dummy);
	code = remove_dots(request_doc, url->pathquery.size);
	if (code != 0) {
		err_code = HTTP_FORBIDDEN;
		goto error_handler;
	}
	if (*request_doc != '/') {
		/* no slash */
		err_code = HTTP_BAD_REQUEST;
		goto error_handler;
	}
	if (isFileInVirtualDir(request_doc)) {
		using_virtual_dir = TRUE;
		RespInstr->IsVirtualFile = 1;
		if (membuffer_assign_str(filename, request_doc) != 0) {
			goto error_handler;
		}
	} else {
		/* try using alias */
		if (is_valid_alias(&gAliasDoc)) {
			alias_grab(alias);
			alias_grabbed = TRUE;
			using_alias = get_alias(request_doc, alias, &finfo);
			if (using_alias == TRUE) {
				finfo.content_type =
				    ixmlCloneDOMString("text/xml");

				if (finfo.content_type == NULL) {
					goto error_handler;
				}
			}
		}
	}
	if (using_virtual_dir) {
		if (req->method != HTTPMETHOD_POST) {
			/* get file info */
			int		ret;
			if ((ret = virtualDirCallback.
			    get_info(filename->buf, req, &extra_headers, &finfo, &extra_func)) != 0) {
			    switch(ret) {
			    case VHAND_ERR__OUT_OF_SERVICE:
			    	err_code = HTTP_SERVICE_UNAVAILABLE;
			    	break;
			    default:
					err_code = HTTP_NOT_FOUND;
				}
				goto error_handler;
			}
			/* try index.html if req is a dir */
			if (finfo.is_directory) {
				if (filename->buf[filename->length - 1] == '/') {
					temp_str = "index.html";
				} else {
					temp_str = "/index.html";
				}
				if (membuffer_append_str(filename, temp_str) !=
				    0) {
					goto error_handler;
				}
				/* get info */
				if ((virtualDirCallback.
				     get_info(filename->buf, req, &extra_headers, &finfo,&extra_func) != UPNP_E_SUCCESS)
				    || finfo.is_directory) {
					err_code = HTTP_NOT_FOUND;
					goto error_handler;
				}
			}
			/* not readable */
			if (!finfo.is_readable) {
				err_code = HTTP_FORBIDDEN;
				goto error_handler;
			}
			/* finally, get content type */
			/* if ( get_content_type(filename->buf, &content_type) != 0 ) */
			/*{ */
			/*  goto error_handler; */
			/* } */
		}
	} else if (!using_alias) {
		int i;
		if (gDocumentRootDir.length == 0) {
			goto error_handler;
		}
		/* */
		/* get file name */
		/* */

		/* filename str */
		UpnpPrintf(UPNP_WARN, HTTP, __FILE__, __LINE__,"%d GET filename %s\r\n", __LINE__, request_doc);
		// Find symbolic link path
		for (i = 0; _symlink[i].symbol != NULL; i++) {
			if (!strncmp(request_doc, _symlink[i].symbol, strlen(_symlink[i].symbol))) {
				// replace symbol by target
				membuffer_assign_str(filename, request_doc);
				membuffer_delete(filename, 0, strlen(_symlink[i].symbol));
				if (membuffer_insert(filename, _symlink[i].target, strlen(_symlink[i].target), 0) != 0)
					goto error_handler;	// out of mem
				break;
			}
		}
		if (!_symlink[i].symbol) {
			// No match, append default root path
			if (membuffer_assign_str(filename, gDocumentRootDir.buf) != 0 ||
			    membuffer_append_str(filename, request_doc) != 0) {
				goto error_handler;	/* out of mem */
			}
		}
		UpnpPrintf(UPNP_WARN, HTTP, __FILE__, __LINE__,"%d GET filename %s\r\n", __LINE__, filename->buf);
		/* remove trailing slashes */
		while (filename->length > 0 &&
		       filename->buf[filename->length - 1] == '/') {
			membuffer_delete(filename, filename->length - 1, 1);
		}
		if (req->method != HTTPMETHOD_POST) {
			/* get info on file */
			if (get_file_info(filename->buf, &finfo) != 0) {
				err_code = HTTP_NOT_FOUND;
				goto error_handler;
			}
			/* try index.html if req is a dir */
			if (finfo.is_directory) {
				if (filename->buf[filename->length - 1] == '/') {
					temp_str = "index.html";
				} else {
					temp_str = "/index.html";
				}
				if (membuffer_append_str(filename, temp_str) !=
				    0) {
					goto error_handler;
				}
				/* get info */
				if (get_file_info(filename->buf, &finfo) != 0 ||
				    finfo.is_directory) {
					err_code = HTTP_NOT_FOUND;
					goto error_handler;
				}
			}
			/* not readable */
			if (!finfo.is_readable) {
				err_code = HTTP_FORBIDDEN;
				goto error_handler;
			}
		}
		/* finally, get content type */
		/*      if ( get_content_type(filename->buf, &content_type) != 0 ) */
		/*      { */
		/*          goto error_handler; */
		/*      } */
	}
	RespInstr->ReadSendSize = finfo.file_length;
	/* Check other header field. */
	if ((code =
	     CheckOtherHTTPHeaders(req, RespInstr,
				   finfo.file_length)) != HTTP_OK) {
		err_code = code;
		goto error_handler;
	}
	if (req->method == HTTPMETHOD_POST) {
		*rtype = RESP_POST;
		err_code = HTTP_OK;
		goto error_handler;
	}
	/*extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo); */
	if (!extra_headers) {
		extra_headers = "";
	}

	/* Check if chunked encoding should be used. */
	if (using_virtual_dir && finfo.file_length == UPNP_USING_CHUNKED) {
		/* Chunked encoding is only supported by HTTP 1.1 clients */
		if (resp_major == 1 && resp_minor == 1) {
			RespInstr->IsChunkActive = 1;
		} else {
			/* The virtual callback indicates that we should use
			 * chunked encoding however the client doesn't support
			 * it. Return with an internal server error. */
			err_code = HTTP_NOT_ACCEPTABLE;
			goto error_handler;
		}
	}
	if (RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
		/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
		/* Transfer-Encoding: chunked */
		if (http_MakeMessage(headers, resp_major, resp_minor,
		    "R" "T" "GKLD" "s" "tcS" "Xc" "sCc",
		    HTTP_PARTIAL_CONTENT,	/* status code */
		    finfo.content_type,	/* content type */
		    RespInstr,	/* range info */
		    RespInstr,	/* language info */
		    "LAST-MODIFIED: ",
		    &finfo.last_modified,
		    X_USER_AGENT, extra_headers) != 0) {
			goto error_handler;
		}
	} else if (RespInstr->IsRangeActive && !RespInstr->IsChunkActive) {
		/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
		/* Transfer-Encoding: chunked */
		if (http_MakeMessage(headers, resp_major, resp_minor,
		    "R" "N" "T" "GLD" "s" "tcS" "Xc" "sCc",
		    HTTP_PARTIAL_CONTENT,	/* status code */
		    RespInstr->ReadSendSize,	/* content length */
		    finfo.content_type,	/* content type */
		    RespInstr,	/* range info */
		    RespInstr,	/* language info */
		    "LAST-MODIFIED: ",
		    &finfo.last_modified,
		    X_USER_AGENT, extra_headers) != 0) {
			goto error_handler;
		}
	} else if (!RespInstr->IsRangeActive && RespInstr->IsChunkActive) {
		/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
		/* Transfer-Encoding: chunked */
		if (http_MakeMessage(headers, resp_major, resp_minor,
		    "RK" "TLD" "s" "tcS" "Xc" "sCc",
		    HTTP_OK,	/* status code */
		    finfo.content_type,	/* content type */
		    RespInstr,	/* language info */
		    "LAST-MODIFIED: ",
		    &finfo.last_modified,
		    X_USER_AGENT, extra_headers) != 0) {
			goto error_handler;
		}
	} else {
		/* !RespInstr->IsRangeActive && !RespInstr->IsChunkActive */
		if (RespInstr->ReadSendSize != 0) {
			/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
			/* Transfer-Encoding: chunked */
			if (http_MakeMessage(headers, resp_major, resp_minor,
			    "R" "N" "TLD" "s" "tcS" "Xc" "sCc",
			    HTTP_OK,	/* status code */
			    RespInstr->ReadSendSize,	/* content length */
			    finfo.content_type,	/* content type */
			    RespInstr,	/* language info */
			    "LAST-MODIFIED: ",
			    &finfo.last_modified,
			    X_USER_AGENT,
			    extra_headers) != 0) {
				goto error_handler;
			}
		} else {
			/* Content-Range: bytes 222-3333/4000  HTTP_PARTIAL_CONTENT */
			/* Transfer-Encoding: chunked */
			if (http_MakeMessage(headers, resp_major, resp_minor,
			    "R" "TLD" "s" "tcS" "Xc" "sCc",
			    HTTP_OK,	/* status code */
			    finfo.content_type,	/* content type */
			    RespInstr,	/* language info */
			    "LAST-MODIFIED: ",
			    &finfo.last_modified,
			    X_USER_AGENT,
			    extra_headers) != 0) {
				goto error_handler;
			}
		}
	}
	if (req->method == HTTPMETHOD_HEAD) {
		*rtype = RESP_HEADERS;
	} else if (using_alias) {
		/* GET xml */
		*rtype = RESP_XMLDOC;
	} else if (using_virtual_dir) {
		*rtype = RESP_WEBDOC;
	} else {
		/* GET filename */
		*rtype = RESP_FILEDOC;
	}
	/* simple get http 0.9 as specified in http 1.0 */
	/* don't send headers */
	if (req->method == HTTPMETHOD_SIMPLEGET) {
		membuffer_destroy(headers);
	}
	err_code = HTTP_OK;

 error_handler:
	osal_free(request_doc);
	ixmlFreeDOMString(finfo.content_type);
	if (err_code != HTTP_OK && alias_grabbed) {
		alias_release(alias);
	}

	return err_code;
}
Example #9
0
INT32 stp_dbg_set_fw_info(UINT8 *issue_info, UINT32 len, ENUM_STP_FW_ISSUE_TYPE issue_type)
{
    ENUM_ASSERT_INFO_PARSER_TYPE type_index;
    UINT8 *tempbuf = NULL;
    UINT32 i  = 0;
    INT32 iRet = 0;

    if (NULL == issue_info) {
        STP_DBG_ERR_FUNC("null issue infor\n");
        return -1;
    }

    STP_DBG_INFO_FUNC("issue type(%d)\n", issue_type);
    g_stp_dbg_cpupcr->issue_type = issue_type;
    osal_memset(&g_stp_dbg_cpupcr->assert_info[0], 0, STP_ASSERT_INFO_SIZE);

    if (STP_FW_ASSERT_ISSUE == issue_type) {
        tempbuf = osal_malloc(len);

        if (!tempbuf) {
            return -2;
        }

        osal_memcpy(&tempbuf[0], issue_info, len);

        for (i = 0; i < len; i++) {
            if (tempbuf[i] == '\0') {
                tempbuf[i] = '?';
            }
        }

        tempbuf[len] = '\0';
#if 0
        STP_DBG_INFO_FUNC("FW assert infor len(%d)\n", len);

        for (i = 0; i < len; i++) {
            if (0 == len % 64) {
                printk("\n");
            }

            printk("%c", tempbuf[i]);
        }

        printk("\n");
#endif

        for (type_index = STP_DBG_ASSERT_INFO; type_index < STP_DBG_PARSER_TYPE_MAX; type_index ++) {
            iRet += _stp_dbg_parser_assert_str(&tempbuf[0], type_index);
        }

        if (iRet) {
            STP_DBG_ERR_FUNC("passert assert infor fail(%d)\n", iRet);
        }

        osal_free(tempbuf);
    } else if (STP_FW_NOACK_ISSUE == issue_type) {
        osal_lock_sleepable_lock(&g_stp_dbg_cpupcr->lock);
        osal_memcpy(&g_stp_dbg_cpupcr->assert_info[0], issue_info, len);
        g_stp_dbg_cpupcr->fwTaskId = 6;
        g_stp_dbg_cpupcr->fwRrq = 0;
        g_stp_dbg_cpupcr->fwIsr = 0;
        osal_unlock_sleepable_lock(&g_stp_dbg_cpupcr->lock);
    } else if (STP_DBG_PROC_TEST == issue_type) {
        osal_lock_sleepable_lock(&g_stp_dbg_cpupcr->lock);
        osal_memcpy(&g_stp_dbg_cpupcr->assert_info[0], issue_info, len);
        g_stp_dbg_cpupcr->fwTaskId = 0;
        g_stp_dbg_cpupcr->fwRrq = 0;
        g_stp_dbg_cpupcr->fwIsr = 0;
        osal_unlock_sleepable_lock(&g_stp_dbg_cpupcr->lock);
    } else if (STP_FW_WARM_RST_ISSUE == issue_type) {
        osal_lock_sleepable_lock(&g_stp_dbg_cpupcr->lock);
        osal_memcpy(&g_stp_dbg_cpupcr->assert_info[0], issue_info, len);
        g_stp_dbg_cpupcr->fwTaskId = 0;
        g_stp_dbg_cpupcr->fwRrq = 0;
        g_stp_dbg_cpupcr->fwIsr = 0;
        osal_unlock_sleepable_lock(&g_stp_dbg_cpupcr->lock);
    } else {
        STP_DBG_ERR_FUNC("invalid issue type(%d)\n", issue_type);
        return -3;
    }

    return iRet;
}
Example #10
0
static void gps_read_data(rt_device_t dev)
{
    uint8_t tmp = 0 ;

    
    while(1)
    {
        if(rt_device_read(dev, 0, &tmp, 1) == 1)
        {

            if (tmp == '$') 
            {
                memset(__GPSBuff.PpBuf[__GPSBuff.Pipe].Buf, 0x0, GPS_BUFF_SIZE);
                 
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Len = 1;
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Buf[0] = '$';
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Flag = 1;	
            }
            else if (tmp == '\n') 
            {
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Buf[__GPSBuff.PpBuf[__GPSBuff.Pipe].Len] = '\n';
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Len++;
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Len %= GPS_BUFF_SIZE;
                __GPSBuff.PpBuf[__GPSBuff.Pipe].Flag = 0;

                        {   
                            if(cms_envar.vam.queue_vam ){
                            
                                sys_msg_st *p_msg;
                                p_msg = osal_malloc(sizeof(sys_msg_st));
                                if (p_msg) {
                                    p_msg->id = VAM_MSG_GPSDATA;
                                    p_msg->len = __GPSBuff.PpBuf[__GPSBuff.Pipe].Len;
                                    p_msg->argv = &__GPSBuff.PpBuf[__GPSBuff.Pipe].Buf;
                                    if (OSAL_STATUS_SUCCESS != vam_add_event_queue_2(&cms_envar.vam, p_msg)){
                                        osal_free(p_msg);
                                    }
                                }
                            }
                        }

                /* Change the pipe index and get new frame. */
                __GPSBuff.Pipe++;
                __GPSBuff.Pipe %= GPS_PIPE;
                
                get_gps = 1 ;
            }
            else 
            {
                if (__GPSBuff.PpBuf[__GPSBuff.Pipe].Flag == 1) 
                {
                    __GPSBuff.PpBuf[__GPSBuff.Pipe].Buf[__GPSBuff.PpBuf[__GPSBuff.Pipe].Len] = tmp;
                    __GPSBuff.PpBuf[__GPSBuff.Pipe].Len++;
                    __GPSBuff.PpBuf[__GPSBuff.Pipe].Len %= GPS_BUFF_SIZE;
                }
            }
        }
        else
        {
            break ;
        }
    }
}