コード例 #1
0
ファイル: ParameterParseNart.c プロジェクト: KHATEEBNSIT/AP
void Print_RefGet(char *name, _PARAM_ITEM_STRUCT *paramS, int client)
{
	char buff[MBUFFER];
	int lc=0, nc=0;
	nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "Reference format: ");
	if(nc>0) lc+=nc;
	// ex format of setting 1 value for all selected items
	if (paramS->numItems<=0 || paramS->numItems>2) {	// error
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s error", name);	
		buff[MBUFFER-1]=0;
		SendIt(client,buff);
		return;
	} 
	// no paramter, get all
	if (!strcmp(paramS->paramName, "config")) {	// config, need to provide address a.addr, no get all
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	config=a.HexAddress16;");
		if(nc>0) lc+=nc;	
	} else {
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s;		-- get all;", name);
		if(nc>0) lc+=nc;
		if (paramS->numItems==1) {
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s=%s.I;", name, paramS->item[0].itemName);
			if(nc>0) lc+=nc;
		} else if (paramS->numItems==2) {
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "%s=%s.I;", name, paramS->item[0].itemName);
			if(nc>0) lc+=nc;
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s=%s.J;", name, paramS->item[1].itemName);
			if(nc>0) lc+=nc;
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s=%s.I,%s.J;", name, paramS->item[0].itemName, paramS->item[1].itemName);
			if(nc>0) lc+=nc;
		}
	}
	buff[MBUFFER-1]=0;
	SendIt(client,buff);
}
コード例 #2
0
ファイル: ParameterParseNart.c プロジェクト: KHATEEBNSIT/AP
void Print_RefSet(char *name, _PARAM_ITEM_STRUCT *paramS, int client)
{
	char buff[MBUFFER];
	int lc=0, nc=0;
	int i,j;
	nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "Reference format: ");
	if(nc>0) lc+=nc;
	if (!strcmp(paramS->paramName, "config")) {	// set config=32bitHexValue; address=16bitHexAddress;
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	config=32bitHexValue; address=16bitHexAddress;");
		if(nc>0) lc+=nc;	
		buff[MBUFFER-1]=0;
		SendIt(client,buff);
		return;
	}

	// ex format of setting 1 value for all selected items
	if (paramS->numItems<=0 || paramS->numItems>3) {	// error
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s error", name);	
		buff[MBUFFER-1]=0;
		SendIt(client,buff);
		return;
	} else {
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s=v.v0", name);	
		if(nc>0) lc+=nc;
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, ",%s.I,%s.J;", paramS->item[1].itemName, paramS->item[2].itemName);
		if(nc>0) lc+=nc;
	}
	// ex format of setting array values
	for (j=1; j<paramS->numItems; j++) {
		nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "\n	%s=v.(", name);
		if(nc>0) lc+=nc;
		for (i=0; i<paramS->item[j].itemMax-paramS->item[j].itemMin+1; i++) {
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, "v%d", i);
			if(nc>0) lc+=nc;
			if (i<paramS->item[j].itemMax-paramS->item[j].itemMin) {
				nc=SformatOutput(&buff[lc],MBUFFER-lc-1, ",");
				if(nc>0) lc+=nc;
			} else {
				nc=SformatOutput(&buff[lc],MBUFFER-lc-1, ")");
				if(nc>0) lc+=nc;
			}
		}
		if (j==1) {
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, ",%s.I;", paramS->item[2].itemName);
			if(nc>0) lc+=nc;
		} else {
			nc=SformatOutput(&buff[lc],MBUFFER-lc-1, ",%s.J;", paramS->item[1].itemName);
			if(nc>0) lc+=nc;
		}
	}
	buff[MBUFFER-1]=0;
	SendIt(client,buff);
}
コード例 #3
0
ファイル: ndasntfs.c プロジェクト: Nevermore2015/ndas4windows
NTSTATUS
SendMessage (
	IN PFILE_OBJECT			ConnectionFileObject,
	IN PNDAS_FC_STATISTICS	SendNdasFcStatistics,
	IN PLARGE_INTEGER		TimeOut,
	IN UINT8				*Buffer, 
	IN UINT32				BufferLength
	)
{
	NTSTATUS		status;
	UINT32			remainDataLength;
	UINT32			chooseDataLength;
	LARGE_INTEGER	startTime;
	LARGE_INTEGER	endTime;

	chooseDataLength = NdasFcChooseTransferSize( SendNdasFcStatistics, BufferLength );

	startTime = NdasCurrentTime();

	remainDataLength = BufferLength;

	do {

		status = SendIt( ConnectionFileObject,
						 Buffer + BufferLength - remainDataLength,
						 (remainDataLength < chooseDataLength) ? remainDataLength : chooseDataLength,
						 NULL,
						 NULL,
						 0,
						 TimeOut );

		if (status != STATUS_SUCCESS) {

			DebugTrace2( 0, Dbg2, ("Error when Send data\n") );

			return status;
		}

		if (remainDataLength > chooseDataLength) {

			remainDataLength -= chooseDataLength;
			
		} else {

			remainDataLength = 0;
		}

	} while (remainDataLength);

	endTime = NdasCurrentTime();

	NdasFcUpdateTrasnferSize( SendNdasFcStatistics, 
						  chooseDataLength, 
						  BufferLength,
						  startTime, 
						  endTime );

	return STATUS_SUCCESS;
}
コード例 #4
0
ファイル: emucomm.cpp プロジェクト: JanD1943/ndas4windows
int
SendPdu(
	IN SOCKET					connSock,
	IN PENCRYPTION_INFO			EncryptInfo,
	IN PNDASDIGEST_INFO			DigestInfo,
	OUT PLANSCSI_PDU_POINTERS	pPdu
){

	PLANSCSI_H2R_PDU_HEADER pHeader;
	int		iAHSegLen, iDataSegLen;
	int		iResult;
	int		iTotalRecved = 0;
	PUCHAR	pPtr = pPdu->pBufferBase;

	pHeader = pPdu->pH2RHeader;
	iAHSegLen = ntohs(pHeader->AHSLen);
	iDataSegLen = ntohl(pHeader->DataSegLen);

	//
	// Encrypt Header.
	//	Assume the buffer contains header + AHS consecutively.
	//
	if(EncryptInfo && EncryptInfo->HeaderEncryptAlgo != 0) {

			Encrypt32(
				(unsigned char*)pHeader,
				sizeof(LANSCSI_H2R_PDU_HEADER) + iAHSegLen,
				(unsigned char *)&EncryptInfo->CHAP_C,
				(unsigned char*)&EncryptInfo->Password64
				);
	}

	//
	// Encrypt Data.
	//
	if(EncryptInfo && EncryptInfo->BodyEncryptAlgo != 0	&& iDataSegLen > 0) {

			Encrypt32(
				(unsigned char*)pPdu->pDataSeg,
				iDataSegLen,
				(unsigned char *)&EncryptInfo->CHAP_C,
				(unsigned char*)&EncryptInfo->Password64
				);
	}

	// Send Request.
	iResult = SendIt(
				connSock,
				(PUCHAR)pHeader,
				sizeof(LANSCSI_H2R_PDU_HEADER) + iAHSegLen + iDataSegLen);
	if(iResult == SOCKET_ERROR) {
		PrintError(WSAGetLastError(), "SendPdu: Send Request ");
		return -1;
	}

	return 0;
}
コード例 #5
0
ファイル: ParameterParseNart.c プロジェクト: KHATEEBNSIT/AP
void Print_RefSetCalTGTPwrDataRate(_PARAM_ITEM_STRUCT *paramS, int client)
{
	char title[MBUFFER], buff[MBUFFER];
	calTGTpwrDataRateTitle(paramS->iMode, title);

	sprintf(buff,"	dataRate: %s\n", title);	
	buff[MBUFFER-1]=0;
    SendIt(client,buff);
}
コード例 #6
0
ファイル: LanScsiCli.cpp プロジェクト: JanD1943/ndas4windows
int
SendRequest(
			SOCKET			connSock,
			PLANSCSI_PDU	pPdu
			)
{
	PLANSCSI_H2R_PDU_HEADER pHeader;
	int						iDataSegLen, iResult;

	pHeader = pPdu->pH2RHeader;
	iDataSegLen = ntohl(pHeader->DataSegLen);

	//
	// Encrypt Header.
	//
	if(iSessionPhase == FLAG_FULL_FEATURE_PHASE
		&& HeaderEncryptAlgo != 0) {
		
		Encrypt32(
			(unsigned char*)pHeader,
			sizeof(LANSCSI_H2R_PDU_HEADER),
			(unsigned char *)&CHAP_C,
			(unsigned char*)&iPassword
			);
	}
	
	//
	// Encrypt Header.
	//
	if(iSessionPhase == FLAG_FULL_FEATURE_PHASE
		&& DataEncryptAlgo != 0
		&& iDataSegLen > 0) {
		
		Encrypt32(
			(unsigned char*)pPdu->pDataSeg,
			iDataSegLen,
			(unsigned char *)&CHAP_C,
			(unsigned char*)&iPassword
			);
	}

	// Send Request.
	iResult = SendIt(
		connSock,
		(PCHAR)pHeader,
		sizeof(LANSCSI_H2R_PDU_HEADER) + iDataSegLen
		);
	if(iResult == SOCKET_ERROR) {
		PrintError(WSAGetLastError(), "SendRequest: Send Request ");
		return -1;
	}
	
	return 0;
}
コード例 #7
0
ファイル: emucomm.cpp プロジェクト: JanD1943/ndas4windows
int
SendBody(
	IN SOCKET			connSock,
	IN PENCRYPTION_INFO	EncryptInfo,
	IN PNDASDIGEST_INFO	DigestInfo,
	IN ULONG			DataTransferLength,
	IN ULONG			DataBufferLength,
	IN PUCHAR			DataBuffer
){

	int		iResult;
	int		iTotalRecved = 0;

	UNREFERENCED_PARAMETER(DigestInfo);

	//
	//	Parameter check
	//

	if(DataBuffer == NULL)
		return -1;
	if(DataTransferLength == 0)
		return 0;
	if(DataBufferLength < DataTransferLength)
		return -1;

	//
	// Encrypt body
	//
	if(EncryptInfo && EncryptInfo->BodyEncryptAlgo != 0) {

			Encrypt32(
				DataBuffer,
				DataTransferLength,
				(unsigned char *)&EncryptInfo->CHAP_C,
				(unsigned char*)&EncryptInfo->Password64
				);
	}

	// Send Request.
	iResult = SendIt(
				connSock,
				DataBuffer,
				DataTransferLength);
	if(iResult == SOCKET_ERROR) {
		PrintError(WSAGetLastError(), "SendBody: Send Request ");
		return -1;
	}

	return iResult;
}
コード例 #8
0
ファイル: am4pmr.c プロジェクト: OS2World/APP-COMM-AM4PM
void ReadModem(PVOID lpVar)
{
   static USHORT i;
   static ULONG n, ulLen, ulStartRecTime;
   static CHAR achHayesBuff[MAXHAYESMSG]; // Buffer for DCE answers
   static USHORT ichHayesBuff=0, usFBuffPos=0;
   static ULONG ulCount;
   static UCHAR buff[RECBUFFLEN], achFileB[RECFBUFFLEN];
   static BOOL bLastCharDLE=FALSE;

   if (fDebug)
      dprintf("Thread for reading started...\n");

   DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);

   for (;;)
   {
      if (DosWaitEventSem(semStopRead, SEM_IMMEDIATE_RETURN)==0)
      {
         if (fDebug)
            dprintf("Reading thread halted. usGlobalState=%u\n", usGlobalState);
         DosResetEventSem(semStopRead, &ulCount);
         DosResetEventSem(semGoOnRead, &ulCount);
         DosPostEventSem(semStopedReading);
         DosWaitEventSem(semGoOnRead, SEM_INDEFINITE_WAIT);
         if (fDebug)
            dprintf("Reading thread goes on... usGlobalState=%u\n", usGlobalState);
         bLastCharDLE=FALSE;
         ichHayesBuff=0;
      }

      if (usGlobalState==GS_ENDING) // Check if it's time to die
      {
         if (fDebug)
            dprintf("\nReading thread dying...\n");
         return;
      }
      
      if (DosRead(hCom, buff, RECBUFFLEN, &n) || !n) // L„s in fr†n porten
         continue;

      for (i=0; i<n; i++)
      {
         if (usGlobalState==GS_READY || usGlobalState==GS_INITREC || usGlobalState==GS_DONE || usGlobalState==GS_INITPLAY)
         {
            switch (buff[i])
            {
            case '\r':
               break;

            case '\n':
               if (ichHayesBuff)
               {
                  achHayesBuff[ichHayesBuff]='\0';
                  if (fDebug)
                     dprintf("DCE: '%s'\n", achHayesBuff);
                  if (usGlobalState==GS_INITREC && strcmp((PCHAR)achHayesBuff, "CONNECT")==0)
                  {
                     usGlobalState=GS_RECORDING;
                     bLastCharDLE=FALSE;
                     ulStartRecTime=GetSysMSecs();
                  }
                  else if (usGlobalState==GS_DONE && strcmp((PCHAR)achHayesBuff, "VCON")==0)
                  {
                     if (fDebug)
                        dprintf("<Ready>\n");
                     usGlobalState=GS_READY;
                  }
                  else if (usGlobalState==GS_INITPLAY)
                  {
                     if (fDebug)
                        dprintf("Play started\n");
                     SendIt(pchSendBuff, ulSendBuffLen);
                     usGlobalState=GS_READY;
                  }
                  QueueData(IM_STRFROMDCE, achHayesBuff, ichHayesBuff+1);
                  ichHayesBuff=0;
               }
               break;

#if 0   // XON/XOFF now handled by OS/2 COM driver
            case 17:
               QueueData(IM_XON, NULL, 0l);
               if (fDebug)
                  dprintf("XON\n");
               break;

            case 19:
               QueueData(IM_XOFF, NULL, 0l);
               if (fDebug)
                  dprintf("XOFF\n");
               break;
#endif
            case 16: // DLE
               if (!bLastCharDLE)
               {
                  bLastCharDLE=TRUE;
                  break;
               }
               else
                  bLastCharDLE=FALSE;
               // Fall through

            default:
               if (bLastCharDLE)
               {
 //               ichHayesBuff=0;
                  bLastCharDLE=FALSE;
                  if (buff[i] >= 32 && (szActiveDLECodes[0]=='\0' || strchr((PCHAR)szActiveDLECodes, buff[i]) != NULL))
                  {
                     QueueData(IM_DLEFROMDCE, buff+i, 1);
                     if (fDebug)
                        dprintf("DCE: <DLE> %c\n", buff[i]);
                  }
                  else
                     if (fDebug)
                        dprintf("DCE: <DLE> %c (ignored)\n", buff[i]);
               }
               else if (ichHayesBuff+1 < MAXHAYESMSG)
               {
                  achHayesBuff[ichHayesBuff]=buff[i];
                  ichHayesBuff++;
               }
               break;
            }
         }
         else if (usGlobalState==GS_RECORDING)
         {
            if (bLastCharDLE)
            {
               bLastCharDLE=FALSE;
               if (buff[i]==3) // ETX
               {
//                SetComXONXOFF(FALSE);
                  usGlobalState=GS_DONE;
                  ichHayesBuff=0;
                  ulRecTime+=GetSysMSecs()-ulStartRecTime;
                  usFBuffPos--;  // Remove stored DLE
               }
               else
               {
                  if (buff[i] >= 32)
                  {
                     if (szActiveDLECodes[0]=='\0' || strchr((PCHAR)szActiveDLECodes, buff[i]) != NULL)
                     {
                        QueueData(IM_DLEFROMDCE, buff+i, 1);
                        if (fDebug)
                           dprintf("DCE: <DLE> %c\n", buff[i]);
                     }
                     else
                        if (fDebug)
                           dprintf("DCE: <DLE> %c (ignored)\n", buff[i]);
                     usFBuffPos--;  // Remove stored DLE
                  }
                  else
                  {
                     if (!bDLEConv)
                        achFileB[usFBuffPos++]=buff[i];
                  }
               }
            }
            else
            {
               bLastCharDLE = buff[i] == 16;
               achFileB[usFBuffPos++]=buff[i];
            }

            if (usFBuffPos >= sizeof achFileB || (usGlobalState!=GS_RECORDING && usFBuffPos > 0))
            {
               if (hRec != 0)
                  DosWrite(hRec, achFileB, usFBuffPos, &ulLen);
               usFBuffPos=0;
            }
         }
      }
   }
}
コード例 #9
0
ファイル: ParameterParseNart.c プロジェクト: KHATEEBNSIT/AP
int ParseIntegerWithParamName(int input, char *name, _PARAM_ITEM_STRUCT *params, int client)
// this function will find the FIRST parameter with parameter name defined in params->paramName in cmd's input th parameter's
// if there are identical paramName.value, program will take the first one and ignore the rest in the input the cmd parameters
// numInGroup is the number of the parameters under this parameter name. 
//		ex. set CalPier=f0.(4,5,6,7)		params[0]->name="f0", numInGroup=4, 
// if numInGroup=0, cmd format is cmd param0; param1;
// if numInGroup=1, cmd format is cmd param0=paramValue0; param1=paramValue1;
// if numInGroup>1, cmd format is cmd param0=f.(paramValue00,paramValue01,paramValue02); param1=f0.(paramValue10,paramValue11,paramValue12);
//						numInGroup=3 for input=0, param[0]->paramName="f"; numInGroup=3 for input=1, param[0]->paramName="f0"
{
	char buff[MBUFFER];
	int ip, np;
	int newvalue;
	char str[MBUFFER], *strPara, *tmp;
	int i, j, iParam, ngot, num=0;
	int status=VALUE_OK;

//	params->numInGroup = -1;
	
	np=CommandParameterValueMany(input);
	if (np==0 && params->numItems>0) {
		if (!strcmp(params->item[0].itemName, "v"))	// it's set, need to have values np>0
			return ERR_VALUE_BAD;
		if (!strcmp(params->paramName, "config"))	// config, need to provide address a.addr
			return ERR_VALUE_BAD;
	}
	if(np>params->numItems)
	{
		sprintf(buff, "too many values for %s.\n",name);
		buff[MBUFFER-1]=0;
		SendIt(client,buff);
		return ERR_VALUE_BAD;
	}
	for(ip=0; ip<np; ip++)
	{
		iParam=-1;
		iParam=-1;
	// ex: in this cmd  set_calPier data_2G_chain0=f0.(1,2,3,4,5,6),f1.(4,5,6,7,8,9); data_2G_chain1=f.(1,2,3,4,5,6),f2.(4,5,6,7,8,9)
	// input 1th param is data_2G_chain1=f.(1,2,3,4,5,6),f2.(4,5,6,7,8,9)
	// param is f1.(4,5,6,7,8,9) for input=0, ip=1, parse out interger array will be 4,5,6,7,8,9
		strcpy(str, CommandParameterValue(input,ip));	
		if (str==0) {
			status = ERR_VALUE_BAD;
			break;
		}
		strPara = strstr(str, ".");
		if (strPara==0) {
			sprintf(buff, "No '.' in Parameter Item %s.\n",str);
			buff[MBUFFER-1]=0;
			SendIt(client,buff);
			status = ERR_VALUE_BAD;
			break;
		}
		*strPara = 0;
		for (i=0; i<params->numItems; i++) {
			if (strcmp(str, params->item[i].itemName)==0) {	// paramName could be f, f0, ....f7 for set_calPier
				iParam = i;
				break;
			}
		}
		if (iParam==-1){
			sprintf(buff, "No item name match with %s.\n",str);
			buff[MBUFFER-1]=0;
			SendIt(client,buff);
			status = ERR_VALUE_BAD;
			break;
		}
		strPara++;						// take out "."
		if (strPara==0) {
			status = ERR_VALUE_BAD;
			break;
		}
		if (*strPara=='(')	strPara++;	// take out "(" for a group of value with (a,b,c)
		
		tmp = strstr(strPara, ")");
		if (tmp) 
			*tmp=',';

		ngot = 0;
		num = 0;
		for (i=0; i<MAX_NUM_PARAM_VALUE; i++) {
			if (strPara==0) 
				break;
			if (iParam==0 && params->isHex==1) {
				ngot=SformatInput(strPara," 0x%x ",&newvalue);
				if(ngot<1)
					ngot=SformatInput(strPara," %x ",&newvalue);
			} else // for "v" is always params->item[0], other items are index, need read in as decimal
				ngot=SformatInput(strPara, "%d,", &newvalue);
			if (ngot==1) {	
				params->item[iParam].values[num++] = newvalue;
				strPara = strstr(strPara, ",");
				if (strPara) strPara++;
			} else {
				break;
			} 
		}
		if (iParam==0 && strcmp(params->item[iParam].itemName,"v")==0) {
			// num of values depends the number of selected items, could be 1 or the number of array
			if (num < params->item[iParam].numInGroup) {
				for (j=num; j<params->item[iParam].numInGroup; j++)
					params->item[iParam].values[j]=0;
			}
			params->item[iParam].numInGroup = num;
			params->item[iParam].itemValueIsSet = 1;
		} else {
			if (params->item[iParam].numInGroup != num) {
				sprintf(buff, "You set one value for %s, need %d\n", params->item[iParam].itemName,  params->item[iParam].numInGroup);
				buff[MBUFFER-1]=0;
				SendIt(client,buff);
				status = ERR_VALUE_BAD;
				break;
			} else
				params->item[iParam].itemValueIsSet = 1;
		}
	}

	if (status==VALUE_OK) {
	// got all value, check if the values are all within limit
		for (i=0; i<params->numItems; i++) {
			if (params->item[i].itemValueIsSet) {
				for (j=0; j<params->item[i].numInGroup; j++) {
					if (params->item[i].values[j]<params->item[i].itemMin || params->item[i].values[j]>params->item[i].itemMax) { 
						sprintf(buff, "item %s.%d value %d is out of limit %d~%d\n", params->item[i].itemName, params->item[i].values[j],
							params->item[i].values[j], params->item[i].itemMin, params->item[i].itemMax);						
						buff[MBUFFER-1]=0;
						SendIt(client,buff);
						status= ERR_VALUE_BAD;
					}
				}	
			}
		}
	}
	return status;
}