コード例 #1
0
static HRESULT cliBuiltInToolGetAddress(char* addressarg, uint32 *pAddress, uint32 *pSize, CLIVariableChangedCallback *pVarcallback, uint32 *pDisplaytype)
{
	HRESULT			hResult = NO_ERROR;
	CLIDescriptor*	variable = 0;
	
	// get address and size of the variable.

	if (cliBuiltInToolGetAddressHexValue(addressarg, pAddress, pSize) == NO_ERROR)
	{
		// the address argument is a hex value.
		*pVarcallback = NULL;
		if (pDisplaytype)
		{
			*pDisplaytype = kCLI_DISPLAYTYPE_HEX;
		}
	}
	else	
	{
		// didn't find a direct address, assume that the passed in argument is the name of a variable
		uint32	temp = 0;
		
		variable = cliLookupDescriptorByName("",addressarg);
		
		if (!variable)
		{
			hResult = E_CLI_BADDESCRIPTORNAME;
			sysLogError(hResult, __LINE__, moduleName);
			return hResult;
		}
		
		//	Check to make sure that this is variable and not a tool.
		kvGetValue(variable, kCLI_Type, (uint32*)&temp);
		if (temp == kCLI_TYPE_TOOL)
		{
			hResult = E_CLI_BADDESCRIPTORTYPE;
			sysLogError(hResult, __LINE__, moduleName);
			return hResult;
		}
		
		//	Get information about the variable.
		kvGetValue(variable, kCLI_VariableSize, pSize);
		kvGetValue(variable, kCLI_Function, (uint32*) pVarcallback);
		kvGetValue(variable, kCLI_Variable, pAddress);
		if (pDisplaytype)
		{
			kvGetValue(variable, kCLI_VariableDisplayType, (uint32*) pDisplaytype);
		}
	}

	return hResult;
}
コード例 #2
0
HRESULT	crRemoveCallback(CALLBACK_DESCRIPTOR* callback)
{
	HRESULT					hResult = NO_ERROR;
	CALLBACK_DESCRIPTOR*	prev = NULL;
	CALLBACK_DESCRIPTOR*	next = NULL;

	if (crFindCallback(CR_FIND_CALLBACK_PREV, 0, 0, callback, &prev) == FALSE)
	{
		hResult = E_AVC_CR_CALLBACK_NOT_FOUND;
		sysLogError(hResult, __LINE__, moduleName);
		return hResult;
	}
	
	// exclusive access for the cr list (mutex)
	hResult = TCMutexLock(crListMutexSemID);
	if (hResult != NO_ERROR) return hResult;
	
	kvGetValue(callback, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next);
	kvSetValue(callback, CALLBACK_DESCRIPTOR_NEXT, 0);
	kvSetValue(prev, CALLBACK_DESCRIPTOR_NEXT, (uint32) next);
	if (crDescHead == callback)
	{
		crDescHead = next;
	}

	// exclusive access for the cr list (mutex)
	TCMutexUnlock(crListMutexSemID);
	
	return hResult;	
}
コード例 #3
0
HRESULT crAddCallback(CALLBACK_DESCRIPTOR* callback)
{
	HRESULT		hResult = NO_ERROR;

	// First check for required key types, these are described in the cr.h
	hResult = kvIsKey(callback, CALLBACK_DESCRIPTOR_TYPE);
	if (hResult != NO_ERROR) return hResult;
	
	hResult = kvIsKey(callback, CALLBACK_DESCRIPTOR_NEXT);
	if (hResult != NO_ERROR) return hResult;
	
#ifdef _SYSDEBUG
	// check in debug mode never to allow adding of the same element twice
	if (crFindCallback(CR_FIND_CALLBACK_THIS, 0, 0, callback, &callback) == TRUE)
	{
		char*	name = NULL;
		kvGetValue(callback, CALLBACK_DESCRIPTOR_NAME, (uint32*) &name);
		sysDebugPrintf("cr error: can't add callback '%s'(0x%08X) twice\n\r", (name) ? name : "un-named", callback);
	}
#endif //_SYSDEBUG
	
	// exclusive access for the cr list (mutex)
	hResult = TCMutexLock(crListMutexSemID);
	if (hResult != NO_ERROR) return hResult;
	
	// need to link this descriptor into the list, by making the crDescHead the next element, and making this the crDescHead
	kvSetValue(callback, CALLBACK_DESCRIPTOR_NEXT, (uint32) crDescHead);
	crDescHead = callback;
	
	// exclusive access for the cr list (mutex)
	TCMutexUnlock(crListMutexSemID);

	return hResult;
}
コード例 #4
0
BOOL kvValueTrue(KEYVALUE* list, uint32 key)
{
	HRESULT		hResult = NO_ERROR;
	uint32		value = 0;
	
	hResult = kvGetValue(list, key, &value);
	if (hResult != NO_ERROR) return FALSE;

	return (value > 0);
}	
コード例 #5
0
// soft glue for calling the first descriptor handler only
HRESULT	avcCallDescriptorHandler(AVC_HEADER *pHeader, PB* packetBlock)
{
	HRESULT							hResult = NO_ERROR;	
	CALLBACK_DESCRIPTOR*			cb = NULL;
	AVC_DESCRIPTORHANDLER_CALLBACK	callback = NULL;

	hResult = crGetCallback(AVC_DESCRIPTORHANDLER_TYPE, 0, &cb);
	if (hResult != NO_ERROR) return E_PKT_AVC_NOT_IMPLEMENTED;

	hResult = kvGetValue(cb, AVC_DESCRIPTORHANDLER_CALLBACK_KEY, (uint32 *) &callback);
	if (hResult != NO_ERROR) return E_PKT_AVC_NOT_IMPLEMENTED;

	// found the appropriate callback so let's make it.
	hResult = (callback) (pHeader, packetBlock);
	return hResult;
}
コード例 #6
0
HRESULT	cliBuiltInTool_ENV(uint32 argc, char** argv)
{
	HRESULT			hResult = NO_ERROR;
	uint32			counter=0;
	CLIDescriptor**	elem=0;
	uint32			index=0;
	char			tempstring[80];

	argc = argc;
	argv = argv;
		
	cliOutputLine("Environment Variables:");
	cliOutputLine("------------------------------------------------------------");
		
	while (lmGetNthElement(cliEnvironmentList, (void **) &elem, counter++, &index) == NO_ERROR)
	{
		char*						varname = 0;
		uint32						value = 0;
		uint32*						pValue = 0;
		uint32						displaytype = 0;
		uint32						displaysize = 32;
		char*						variablefields = NULL;
		char						spacer[40];
		CLIVariableChangedCallback	varcallback = 0;
			
		kvGetValue(*elem, kCLI_Name, (uint32*)&varname);
		kvGetValue(*elem, kCLI_Variable,(uint32*)&pValue);
		kvGetValue(*elem, kCLI_VariableDisplayType, &displaytype); 
		kvGetValue(*elem, kCLI_VariableSize, &displaysize);
		kvGetValue(*elem, kCLI_Function, (uint32*)&varcallback);
		kvGetValue(*elem, kCLI_VariableBitFields, (uint32*)&variablefields);
				
		memset(spacer,' ',ARRAYSIZE(spacer));
		spacer[24-strlen(varname)]=0;
		
		if (varcallback)
		{
			//	For virtual variable, it will have a varcallback, that we can ask for the value of the variable.
			hResult = (varcallback)(kCLI_VariableCallbackOperation_GET,varname,0L,&value);
			if (hResult != NO_ERROR)
			{
				sprintf(tempstring,"%s%s= N/A",varname,spacer);
				cliOutputLine(tempstring);
				hResult = NO_ERROR;
				continue;
			}	
		}
		else
		{
			//	For normal variables which just point to a place in memory.
			if (pValue)
			{	
				value=*pValue;
			}	
		}
		
		if (varname)
		{
			if (kCLI_DISPLAYTYPE_HEX==displaytype)
			{
				switch (displaysize)
				{
					case 32:
						sprintf(tempstring,"%s%s= 0x%08X",varname,spacer,value);
						break;
					
					case 24:
						sprintf(tempstring,"%s%s= 0x%06X",varname,spacer,value);	
						break;
					
					case 16:
						sprintf(tempstring,"%s%s= 0x%04X",varname,spacer,value);	
						break;
					
					case 8:
						sprintf(tempstring,"%s%s= 0x%02X",varname,spacer,value);	
						break;
				}
				cliOutputRaw(tempstring);
			}
			
			if (kCLI_DISPLAYTYPE_DECIMAL==displaytype)
			{
				sprintf(tempstring,"%s%s= %d",varname,spacer,value);
				cliOutputRaw(tempstring);	
			}
			
			if (kCLI_DISPLAYTYPE_BOOLEAN==displaytype)
			{
				sprintf(tempstring,"%s%s= ",varname,spacer);
				if (value)
				{
					strcat(tempstring,"true");	
				}
				else
				{
					strcat(tempstring,"false");
				}	
				cliOutputRaw(tempstring);
			}
			
			if (kCLI_DISPLAYTYPE_BINARY==displaytype)
			{
				uint32	i = 0;
				
				sprintf(tempstring,"%s%s= ",varname,spacer);
				for (i = displaysize; i > 0; i--)
				{
					uint32	mask = (uint32) (1 << (i-1));
					if ((value) & mask)
					{
						strcat(tempstring,"1");	
					}
					else
					{
						strcat(tempstring,"0");
					}
				}
				cliOutputRaw(tempstring);	
			}
			
			// Check to see if we should display fields in the variables.
			if (variablefields)
			{
				cliPrintVariableFields(value,variablefields);
			}
			cliOutputLine(" ");
		}
		
		lmReleaseElement(cliEnvironmentList,index);		
	}

	return hResult;
}
コード例 #7
0
HRESULT avcHandleCallback(AVC_HEADER *pHeader, PB *packetBlock)
{
	HRESULT	 				hResult = NO_ERROR;
	uint32	 				index = 0;
	uint32					subunitidcounter = 0;
	CALLBACK_DESCRIPTOR*	cb = NULL;
	AVC_SUBUNIT_CALLBACK	callback = NULL;
	BOOL					bFound = FALSE;

#ifdef _SYSDEBUG
	if (sysDebugIsEnabled(SYSDEBUG_TRACE_AVC))
	{
		if (avcUnitCliIsPrintMode(AVC_UNIT_PRINT_RCV_RAW))
		{
			avcUnitCliPrintPacketBlockRawData(pHeader->ctype, packetBlock);
		}
	}
#endif //_SYSDEBUG

	DO_FOREVER
	{
		hResult = crGetCallback(AVC_SUBUNIT_TYPE, index++, &cb);
		if (hResult != NO_ERROR) break;

		hResult = kvIsValue(cb, AVC_SUBUNIT_SUBUNITTYPE_KEY, pHeader->addrSubunit.subunit_type);
		if (hResult != NO_ERROR) continue;
		
		hResult = kvGetValue(cb, AVC_SUBUNIT_ID_KEY, &subunitidcounter);
		if (hResult != NO_ERROR) continue;

		if (subunitidcounter != AVC_SU_ID_IGNORE &&
			subunitidcounter != pHeader->addrSubunit.subunit_ID) continue;
			
		hResult = kvGetValue(cb, AVC_SUBUNIT_CALLBACK_KEY, (uint32 *) &callback);
		if (hResult != NO_ERROR) break;

		// found the appropriate callback so let's make it.
		hResult = (callback) (pHeader, packetBlock);
		bFound = TRUE;
		break;
	}

	if (bFound == FALSE)
	{
		SYS_DEBUG(SYSDEBUG_TRACE_AVC | SYSDEBUG_TRACE_ERRORS, 
				  "avcHandleCallback: Could not find callback for registered subunittype\n\r");
#ifdef _SYSDEBUG
		if (avcCtypeIsResponse(pHeader->ctype))
		{
			if (sysDebugIsEnabled(SYSDEBUG_TRACE_AVC))
			{
				sysDebugPrintf("avcHandleCallback: Response\n\r");
				avcUnitCliPrintHeader(pHeader);
			}
		}
#endif //_SYSDEBUG
		hResult = E_PKT_AVC_NOT_IMPLEMENTED;
		sysLogError(hResult, __LINE__, moduleName);
		return hResult;
	}

	return hResult;
}
コード例 #8
0
BOOL crFindCallback(uint32 mode, uint32 type, uint32 index, CALLBACK_DESCRIPTOR* findcallback, CALLBACK_DESCRIPTOR** callback)
{
	HRESULT					hResult = NO_ERROR;
	CALLBACK_DESCRIPTOR*	current = crDescHead;
	CALLBACK_DESCRIPTOR*	next = NULL;
	uint32					counter = 0;
	uint32					foundtype = 0;
	BOOL					bFound = FALSE;

	// exclusive access for the cr list (mutex)
	hResult = TCMutexLock(crListMutexSemID);
	if (hResult != NO_ERROR) return FALSE;
	
	while (current)
	{
		switch (mode)
		{
			case CR_FIND_CALLBACK_TYPE:
				kvGetValue(current, CALLBACK_DESCRIPTOR_TYPE, &foundtype);
				if (foundtype == type)
				{
					bFound = (counter == index);
					counter++;	
				}
				break;
			
			case CR_FIND_CALLBACK_FIRST:
				bFound = TRUE;
				break;

			case CR_FIND_CALLBACK_THIS:
				bFound = (current == findcallback);
				break;

			case CR_FIND_CALLBACK_PREV:
				kvGetValue(current, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next);
				if (!next) break;
				bFound = (next == findcallback);
				break;

			case CR_FIND_CALLBACK_NEXT:
				kvGetValue(findcallback, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next);
				current = next;
				if (!current) continue;
				bFound = TRUE;
				break;
		}
		
		if (bFound == TRUE)
		{
			*callback = current;
			break;
		}

		kvGetValue(current, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next);
		if (!next) break;
						
		current = next;
	}
	
	// exclusive access for the cr list (mutex)
	TCMutexUnlock(crListMutexSemID);

	return bFound;
}