SAT_returnState hk_app(tc_tm_pkt *pkt) {

    if(!C_ASSERT(pkt != NULL && pkt->data != NULL) == true) { return SATR_ERROR; }
    if(!C_ASSERT(pkt->ser_subtype == TC_HK_REPORT_PARAMETERS ||
                 pkt->ser_subtype == TM_HK_PARAMETERS_REPORT) == true) {return SATR_ERROR; }

    if(pkt->ser_subtype == TC_HK_REPORT_PARAMETERS) {

        tc_tm_pkt *temp_pkt = 0;
        HK_struct_id sid = (HK_struct_id)pkt->data[0];

        hk_crt_empty_pkt_TM(&temp_pkt, (TC_TM_app_id)pkt->dest_id, sid);

        if(!C_ASSERT(temp_pkt != NULL) == true) {
            return SATR_ERROR;
        }

        route_pkt(temp_pkt);

    } else if(pkt->ser_subtype == TM_HK_PARAMETERS_REPORT) {

        const SAT_returnState res = hk_parameters_report(pkt->app_id, (HK_struct_id)pkt->data[0],  pkt->data, pkt->len);

        if(res == SATR_OK) {
            pkt->verification_state = SATR_OK;
        }
    }

    return SATR_OK;
}
Esempio n. 2
0
HRESULT GetImageInfoFromPEHeader( HANDLE hProcess, void* dllBase, uint16_t& machine, uint32_t& size, Address& prefBase )
{
    IMAGE_DOS_HEADER    dosHeader = { 0 };
    SIZE_T              cActual = 0;

    if ( !::ReadProcessMemory( hProcess, dllBase, &dosHeader, sizeof dosHeader, &cActual ) ) 
    {
        _ASSERT( !"Failed to read IMAGE_DOS_HEADER from loaded module" );
        return GetLastHr();
    }

    IMAGE_NT_HEADERS    ntHeaders = { 0 };
    void*               ntHeadersAddr = (void*) ((DWORD_PTR) dosHeader.e_lfanew + (DWORD_PTR) dllBase);
    
    if ( !::ReadProcessMemory( hProcess, ntHeadersAddr, &ntHeaders, sizeof ntHeaders, &cActual ) ) 
    {
        _ASSERT( !"Failed to read IMAGE_NT_HEADERS from loaded module" );
        return GetLastHr();
    }

    // These fields line up for 32 and 64-bit IMAGE_NT_HEADERS; make sure of it
    // otherwise, we would have had to check fileHeader.Characteristics & IMAGE_FILE_32BIT_MACHINE
    C_ASSERT( &((IMAGE_NT_HEADERS32*) 0)->OptionalHeader.SizeOfImage == 
              &((IMAGE_NT_HEADERS64*) 0)->OptionalHeader.SizeOfImage );
    C_ASSERT( &((IMAGE_NT_HEADERS32*) 0)->FileHeader.Machine == 
              &((IMAGE_NT_HEADERS64*) 0)->FileHeader.Machine );

    machine = ntHeaders.FileHeader.Machine;
    size = ntHeaders.OptionalHeader.SizeOfImage;
    prefBase = ntHeaders.OptionalHeader.ImageBase;

    return S_OK;
}
Esempio n. 3
0
PmReturn_t
seqiter_new(pPmObj_t pobj, pPmObj_t *r_pobj)
{
    PmReturn_t retval;
    uint8_t *pchunk;
    pPmSeqIter_t psi;

    C_ASSERT(pobj != C_NULL);
    C_ASSERT(*r_pobj != C_NULL);

    /* Raise a TypeError if pobj is not a sequence */
    if ((OBJ_GET_TYPE(pobj) != OBJ_TYPE_STR)
            && (OBJ_GET_TYPE(pobj) != OBJ_TYPE_TUP)
            && (OBJ_GET_TYPE(pobj) != OBJ_TYPE_LST))
    {
        PM_RAISE(retval, PM_RET_EX_TYPE);
        return retval;
    }

    /* Alloc a chunk for the sequence iterator obj */
    retval = heap_getChunk(sizeof(PmSeqIter_t), &pchunk);
    PM_RETURN_IF_ERROR(retval);

    /* Set the sequence iterator's fields */
    psi = (pPmSeqIter_t)pchunk;
    OBJ_SET_TYPE(psi, OBJ_TYPE_SQI);
    psi->si_sequence = pobj;
    psi->si_index = 0;

    *r_pobj = (pPmObj_t)psi;
    return retval;
}
Esempio n. 4
0
PmReturn_t
seqiter_getNext(pPmObj_t pobj, pPmObj_t *r_pitem)
{
    PmReturn_t retval;
    int16_t length;

    C_ASSERT(pobj != C_NULL);
    C_ASSERT(*r_pitem != C_NULL);
    C_ASSERT(OBJ_GET_TYPE(pobj) == OBJ_TYPE_SQI);

    /*
     * Raise TypeError if sequence iterator's object is not a sequence
     * otherwise, the get sequence's length
     */
    retval = seq_getLength(((pPmSeqIter_t)pobj)->si_sequence, &length);
    PM_RETURN_IF_ERROR(retval);

    /* Raise StopIteration if at the end of the sequence */
    if (((pPmSeqIter_t)pobj)->si_index == length)
    {
        /* Make null the pointer to the sequence */
        ((pPmSeqIter_t)pobj)->si_sequence = C_NULL;
        PM_RAISE(retval, PM_RET_EX_STOP);
        return retval;
    }

    /* Get the item at the current index */
    retval = seq_getSubscript(((pPmSeqIter_t)pobj)->si_sequence,
                              ((pPmSeqIter_t)pobj)->si_index, r_pitem);

    /* Increment the index */
    ((pPmSeqIter_t)pobj)->si_index++;

    return retval;
}
// driver entry
NTSTATUS DriverEntry(__in PDRIVER_OBJECT pDriverObject,__in PUNICODE_STRING pRegPath)
{
	PAGED_CODE();

	C_ASSERT(sizeof(CHidData) == 0x6c);
	C_ASSERT(sizeof(CDeviceExtension) == 0x200);

	NTSTATUS statusRet = STATUS_SUCCESS;

	AppleDebugPrint(DBGLEVEL_INFO,"Enter AppleKeyboard DriverEntry %p,%p\n",pDriverObject,pRegPath);

	pDriverObject->MajorFunction[IRP_MJ_CREATE] = AppleKeyboardCreate;
	pDriverObject->MajorFunction[IRP_MJ_CLOSE] = AppleKeyboardClose;
	pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AppleKeyboardIoControl;
	pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = AppleKeyboardInternalIoControl;
	pDriverObject->MajorFunction[IRP_MJ_PNP] = AppleKeyboardPnp;
	pDriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = AppleKeyboardFlush;
	pDriverObject->MajorFunction[IRP_MJ_POWER] = AppleKeyboardPower;
	pDriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = AppleKeyboardSystemControl;
	pDriverObject->DriverUnload = AppleKeyboardUnload;
	pDriverObject->DriverExtension->AddDevice = AppleKeyboardAddDevice;

	g_regPath.Length = pRegPath->Length;
	g_regPath.MaximumLength = g_regPath.Length + sizeof(WCHAR);
	g_regPath.Buffer = static_cast<PWCH>(ExAllocatePoolWithTag(PagedPool,g_regPath.MaximumLength,'Appl'));
	if(g_regPath.Buffer)
		RtlCopyMemory(g_regPath.Buffer,pRegPath->Buffer,pRegPath->Length);
	else
		statusRet = STATUS_INSUFFICIENT_RESOURCES;

	AppleDebugPrint(DBGLEVEL_INFO,"Leave DriverEntry 0x%08x\n",statusRet);

	return statusRet;
}
Esempio n. 6
0
PmReturn_t
float_print(pPmObj_t pf)
{
    uint8_t tBuffer[32];
    uint8_t bytesWritten;
    uint8_t i;
    PmReturn_t retval = PM_RET_OK;

    C_ASSERT(pf != C_NULL);

    /* Raise TypeError if obj is not an float */
    if (OBJ_GET_TYPE(pf) != OBJ_TYPE_FLT)
    {
        PM_RAISE(retval, PM_RET_EX_TYPE);
        return retval;
    }

    /* #196: Changed to use snprintf */
    bytesWritten = snprintf((char *)&tBuffer, 32, "%f", ((pPmFloat_t) pf)->val);

    /* Sanity check */
    C_ASSERT(bytesWritten != 0);
    C_ASSERT(bytesWritten < sizeof(tBuffer));

    for (i = (uint8_t)0; i < bytesWritten; i++)
    {
        retval = plat_putByte(tBuffer[i]);
        PM_RETURN_IF_ERROR(retval);
    }
    return PM_RET_OK;
}
// Helper method for updating an interface dispatch cache entry atomically. See comments by the usage of
// this method for the details of why we need this. If a racing update is detected false is returned and the
// update abandoned. This is necessary since it's not safe to update a valid cache entry (one with a non-NULL
// m_pInstanceType field) outside of a GC.
static bool UpdateCacheEntryAtomically(InterfaceDispatchCacheEntry *pEntry,
                                       EEType * pInstanceType,
                                       void * pTargetCode)
{
    C_ASSERT(sizeof(InterfaceDispatchCacheEntry) == (sizeof(void*) * 2));
    C_ASSERT(offsetof(InterfaceDispatchCacheEntry, m_pInstanceType) < offsetof(InterfaceDispatchCacheEntry, m_pTargetCode));

    return UpdatePointerPairAtomically(pEntry, pInstanceType, pTargetCode, true) == NULL;
}
Esempio n. 8
0
static
int32_t
IDNA_FlagsToICU
(
	DWORD dwFlags
)
{
	C_ASSERT(IDN_ALLOW_UNASSIGNED == UIDNA_ALLOW_UNASSIGNED);
	C_ASSERT(IDN_USE_STD3_ASCII_RULES == UIDNA_USE_STD3_RULES);
	return dwFlags;
}
Esempio n. 9
0
PmReturn_t
thread_new(pPmObj_t pframe, pPmObj_t *r_pobj)
{
    PmReturn_t retval = PM_RET_OK;
    pPmThread_t pthread = C_NULL;

    C_ASSERT(pframe != C_NULL);

    /* If it's not a frame, raise TypeError */
    if (OBJ_GET_TYPE(pframe) != OBJ_TYPE_FRM)
    {
        PM_RAISE(retval, PM_RET_EX_TYPE);
        return retval;
    }

    /* Allocate a thread */
    retval = heap_getChunk(sizeof(PmThread_t), (uint8_t **)r_pobj);
    PM_RETURN_IF_ERROR(retval);

    /* Set type, frame and initialize status */
    pthread = (pPmThread_t)*r_pobj;
    OBJ_SET_TYPE(pthread, OBJ_TYPE_THR);
    pthread->pframe = (pPmFrame_t)pframe;
    pthread->interpctrl = INTERP_CTRL_CONT;

    return retval;
}
Esempio n. 10
0
PmReturn_t
dict_clear(pPmObj_t pdict)
{
    PmReturn_t retval = PM_RET_OK;

    C_ASSERT(pdict != C_NULL);

    /* Raise TypeError if arg is not a dict */
    if (OBJ_GET_TYPE(pdict) != OBJ_TYPE_DIC)
    {
        PM_RAISE(retval, PM_RET_EX_TYPE);
        return retval;
    }

    /* clear length */
    ((pPmDict_t)pdict)->length = 0;

    /* Free the keys and values seglists if needed */
    if (((pPmDict_t)pdict)->d_keys != C_NULL)
    {
        PM_RETURN_IF_ERROR(seglist_clear(((pPmDict_t)pdict)->d_keys));
        PM_RETURN_IF_ERROR(heap_freeChunk((pPmObj_t)
                                          ((pPmDict_t)pdict)->d_keys));
        ((pPmDict_t)pdict)->d_keys = C_NULL;
    }
    if (((pPmDict_t)pdict)->d_vals != C_NULL)
    {
        PM_RETURN_IF_ERROR(seglist_clear(((pPmDict_t)pdict)->d_vals));
        retval = heap_freeChunk((pPmObj_t)((pPmDict_t)pdict)->d_vals);
        ((pPmDict_t)pdict)->d_vals = C_NULL;
    }
    return retval;
}
Esempio n. 11
0
// シェーダごとの初期化
BOOL CHemiLightShader::InitInternal(izanagi::graph::CGraphicsDevice* pDevice)
{
	UNUSED_ALWAYS(pDevice);
	IZ_ASSERT(m_pEffect != IZ_NULL);

	if (!GetCommonParameterHandles()) {
		return IZ_FALSE;
	}

	static const char* PARAM_NAME[] = {
		"g_vEye",
		"g_vMtrlDiffuse",
		"g_vAxis",
		"g_vUpColor",
		"g_vDownColor",
	};
	C_ASSERT(COUNTOF(PARAM_NAME) == HANDLE_NUM);

	IZ_BOOL result = GetParameterByName(
						HANDLE_NUM,
						m_hHandles,
						PARAM_NAME);
	IZ_ASSERT(result);

	return result;
}
Esempio n. 12
0
/**
 * This functions handles an incoming ECSS packet.
 * If the ECSS packet is part of a large data transfer consisting from
 * several sequential ECSS packets, it handles them automatically.
 *
 * In other words, there is no need to explicitly check for a fragmented data
 * transfer.
 *
 * @param payload the received payload
 * @param payload_size the size of the payload
 * @return SATR_OK if all went ok or appropriate error code
 */
SAT_returnState
rx_ecss (uint8_t *payload, const uint16_t payload_size)
{
  SAT_returnState ret;
  tc_tm_pkt *pkt;

  pkt = get_pkt (payload_size);

  if (!C_ASSERT(pkt != NULL)) {
    return SATR_ERROR;
  }
  if (unpack_pkt (payload, pkt, payload_size) == SATR_OK) {
    ret = route_pkt (pkt);
  }

  TC_TM_app_id dest = 0;

  if(pkt->type == TC) {
    dest = pkt->app_id;
  }
  else if(pkt->type == TM) {
    dest = pkt->dest_id;
  }

  if(dest == SYSTEM_APP_ID) {
      free_pkt(pkt);
  }

  return ret;
}
Esempio n. 13
0
/* Warning: Can be called in interrupt context! */
PmReturn_t
pm_vmPeriodic(uint16_t usecsSinceLastCall)
{
    /*
     * Add the full milliseconds to pm_timerMsTicks and store additional
     * microseconds for the next run. Thus, usecsSinceLastCall must be
     * less than 2^16-1000 so it will not overflow usecResidual.
     */
    static uint16_t usecResidual = 0;

    C_ASSERT(usecsSinceLastCall < 64536);

    usecResidual += usecsSinceLastCall;
    while (usecResidual >= 1000)
    {
        usecResidual -= 1000;
        pm_timerMsTicks++;
    }

    /* Check if enough time has passed for a scheduler run */
    if ((pm_timerMsTicks - pm_lastRescheduleTimestamp)
        >= PM_THREAD_TIMESLICE_MS)
    {
        interp_setRescheduleFlag((uint8_t)1);
        pm_lastRescheduleTimestamp = pm_timerMsTicks;
    }
    return PM_RET_OK;
}
Esempio n. 14
0
PmReturn_t
dict_delItem(pPmObj_t pdict, pPmObj_t pkey)
{
    PmReturn_t retval = PM_RET_OK;
    int16_t indx = 0;

    C_ASSERT(pdict != C_NULL);

    /* Check for matching key */
    retval = seglist_findEqual(((pPmDict_t)pdict)->d_keys, pkey, &indx);

    /* Raise KeyError if key is not found */
    if (retval == PM_RET_NO)
    {
        PM_RAISE(retval, PM_RET_EX_KEY);
    }

    /* Return any other error */
    PM_RETURN_IF_ERROR(retval);

    /* Remove the key and value */
    retval = seglist_removeItem(((pPmDict_t)pdict)->d_keys, indx);
    PM_RETURN_IF_ERROR(retval);
    retval = seglist_removeItem(((pPmDict_t)pdict)->d_vals, indx);

    /* Reduce the item count */
    ((pPmDict_t)pdict)->length--;

    return retval;
}
Esempio n. 15
0
PmReturn_t
obj_repr(pPmObj_t pobj, pPmObj_t *r_pstr)
{
    uint8_t tBuffer[32];
    PmReturn_t retval = PM_RET_OK;
    uint8_t const *pcstr = (uint8_t *)tBuffer;;

    C_ASSERT(pobj != C_NULL);

    switch (OBJ_GET_TYPE(pobj))
    {
    case OBJ_TYPE_INT:
        retval = sli_ltoa10(((pPmInt_t)pobj)->val, tBuffer, sizeof(tBuffer));
        PM_RETURN_IF_ERROR(retval);
        retval = string_new(&pcstr, r_pstr);
        break;

#ifdef HAVE_FLOAT
    case OBJ_TYPE_FLT:
        /* #212: Use homebrew float formatter */
        retval = sli_ftoa(((pPmFloat_t)pobj)->val, tBuffer, sizeof(tBuffer));
        sli_strlen((char *)tBuffer);
        retval = string_new(&pcstr, r_pstr);
        break;
#endif /* HAVE_FLOAT */

    default:
        /* Otherwise raise a TypeError */
        PM_RAISE(retval, PM_RET_EX_TYPE);
        break;
    }

    return retval;
}
Esempio n. 16
0
BOOL
CNdasUnitDeviceCreator::IsConsistentDIB(
    CONST NDAS_DIB_V2* pDIBv2)
{
    XTLASSERT(!IsBadReadPtr(pDIBv2, sizeof(NDAS_DIB_V2)));

    BOOL bConsistent = FALSE;
    const NDAS_DEVICE_ID& deviceID = m_pDevice->GetDeviceId();
    const DWORD unitNo = m_dwUnitNo;

    for (DWORD i = 0; i < pDIBv2->nDiskCount + pDIBv2->nSpareCount  && i < NDAS_MAX_UNITS_IN_V2; ++i)
    {
        C_ASSERT(
            sizeof(deviceID.Node) ==
            sizeof(pDIBv2->UnitDisks[i].MACAddr));

        if (0 == memcmp(
                    deviceID.Node,
                    pDIBv2->UnitDisks[i].MACAddr,
                    sizeof(deviceID.Node)) &&
                unitNo == pDIBv2->UnitDisks[i].UnitNumber)
        {
            bConsistent = TRUE;
        }
    }
    return bConsistent;
}
Esempio n. 17
0
/* Inserts in order a chunk into the free list.  Caller adjusts heap state */
static PmReturn_t
heap_linkToFreelist(pPmHeapDesc_t pchunk)
{
    uint16_t size;
    pPmHeapDesc_t pscan;

    /* Ensure the object is already free */
    C_ASSERT(OBJ_GET_FREE(pchunk) != 0);

    /* If free list is empty, add to head of list */
    if (pmHeap.pfreelist == C_NULL)
    {
        pmHeap.pfreelist = pchunk;
        pchunk->next = C_NULL;
        pchunk->prev = C_NULL;

        return PM_RET_OK;
    }

    /* Scan free list for insertion point */
    pscan = pmHeap.pfreelist;
    size = OBJ_GET_SIZE(pchunk);
    while ((OBJ_GET_SIZE(pscan) < size) && (pscan->next != C_NULL))
    {
        pscan = pscan->next;
    }

    /*
     * Insert chunk after the scan chunk (next is NULL).
     * This is a slightly rare case where the last chunk in the free list
     * is smaller than the chunk being freed.
     */
    if (size > OBJ_GET_SIZE(pscan))
    {
        pchunk->next = pscan->next;
        pscan->next = pchunk;
        pchunk->prev = pscan;
    }

    /* Insert chunk before the scan chunk */
    else
    {
        pchunk->next = pscan;
        pchunk->prev = pscan->prev;

        /* If chunk will be first item in free list */
        if (pscan->prev == C_NULL)
        {
            pmHeap.pfreelist = pchunk;
        }
        else
        {
            pscan->prev->next = pchunk;
        }
        pscan->prev = pchunk;
    }

    return PM_RET_OK;
}
Esempio n. 18
0
SAT_returnState HLDLC_deframe(uint8_t *buf_in,
                              uint8_t *buf_out,
                              const uint16_t size_in,
                              uint16_t *size_out) {

    if(!C_ASSERT(buf_in != 0 && buf_out != 0) == true)    { return SATR_ERROR; }

    uint16_t cnt = 0;

  //  for(uint16_t i = 1; i < size_in; i++) {
  //          if(buf_in[i] == HLDLC_START_FLAG) {
  //              cnt = 0;

   // }

    for(uint16_t i = 0; i < size_in; i++) {

        uint8_t c = buf_in[i];

        if(c == HLDLC_START_FLAG) {
            cnt = 0;
        } else if(c == HLDLC_STOP_FLAG) {
            *size_out = cnt;
            return SATR_EOT;
        } else if(c == HLDLC_CONTROL_FLAG) {
            i++;

            if(c == 0x5E) {
              buf_out[cnt++] = 0x7E;
            } else if(c == 0x5D) {
              buf_out[cnt++] = 0x7D;
            } else if(c== 0x5C) {
              buf_out[cnt++] = 0x7C;
            } else {
              return SATR_ERROR;
            }
        } else {
            buf_out[cnt++] = c;
        }

        if(!C_ASSERT(cnt < MAX_HLDLC_PKT_SIZE - 1) == true) {
          return SATR_ERROR;
        }
    }
    return SATR_ERROR;
}
SAT_returnState hk_crt_empty_pkt_TM(tc_tm_pkt **pkt, const TC_TM_app_id app_id, const HK_struct_id sid) {

    *pkt = get_pkt(PKT_NORMAL);
    if(!C_ASSERT(*pkt != NULL) == true) { return SATR_ERROR; }

    hk_crt_pkt_TM(*pkt, app_id, sid);
    return SATR_OK;
}
Esempio n. 20
0
static t_block	*cycle_fd(t_block **train, const int fd)
{
	t_block			*tmp;

	tmp = *train;
	while (tmp && tmp->fd != fd)
		tmp = tmp->next;
	if (!tmp)
	{
		C_ASSERT(tmp = (t_block *)ft_memalloc(sizeof(t_block)));
		tmp->fd = fd;
		C_ASSERT(tmp->str = ft_strnew(0));
		tmp->next = *train;
		*train = tmp;
	}
	return (tmp);
}
Esempio n. 21
0
PmReturn_t
dict_update(pPmObj_t pdestdict, pPmObj_t psourcedict, uint8_t omit_underscored)
{
    PmReturn_t retval = PM_RET_OK;
    int16_t i;
    pPmObj_t pkey;
    pPmObj_t pval;

    C_ASSERT(pdestdict != C_NULL);
    C_ASSERT(psourcedict != C_NULL);

    /* If it's not a dict, raise TypeError */
    if (OBJ_GET_TYPE(pdestdict) != OBJ_TYPE_DIC)
    {
        PM_RAISE(retval, PM_RET_EX_TYPE);
        return retval;
    }

    /* If it's not a dict, raise TypeError */
    if (OBJ_GET_TYPE(psourcedict) != OBJ_TYPE_DIC)
    {
        PM_RAISE(retval, PM_RET_EX_TYPE);
        return retval;
    }

    /* Iterate over the add-on dict */
    for (i = 0; i < ((pPmDict_t)psourcedict)->length; i++)
    {
        /* Get the key,val from the add-on dict */
        retval = seglist_getItem(((pPmDict_t)psourcedict)->d_keys, i, &pkey);
        PM_RETURN_IF_ERROR(retval);
        retval = seglist_getItem(((pPmDict_t)psourcedict)->d_vals, i, &pval);
        PM_RETURN_IF_ERROR(retval);

        if (!(omit_underscored && (OBJ_GET_TYPE(pkey) == OBJ_TYPE_STR)
              && ((pPmString_t)pkey)->val[0] == '_'))
        {
            /* Set the key,val to the destination dict */
            retval = dict_setItem(pdestdict, pkey, pval);
            PM_RETURN_IF_ERROR(retval);
        }
    }

    return retval;
}
Esempio n. 22
0
 template < typename _T_REG_UNION > __forceinline void writeRegisterNoFence (
     _T_REG_UNION RegUnion
     ) const throw ()
 {
     C_ASSERT(sizeof(UINT32) == sizeof(ULONG));
     ULONG* const regPtr = reinterpret_cast<ULONG*>(
         ULONG_PTR(this->basePtr) + ULONG(RegUnion.OFFSET));
     ::WRITE_REGISTER_NOFENCE_ULONG(regPtr, RegUnion.AsUint32);
 } // writeRegisterNoFence<...> ( _T_REG_UNION )
Esempio n. 23
0
PNDAS_LOGICALUNIT_DESCRIPTOR
WINAPI
NdasPortCtlBuildNdasAtaDeviceDescriptor(
	__in NDAS_LOGICALUNIT_ADDRESS LogicalUnitAddress,
	__in ULONG LogicalUnitFlags,
	__in CONST NDAS_DEVICE_IDENTIFIER* DeviceIdentifier,
	__in ULONG NdasDeviceFlagMask,
	__in ULONG NdasDeviceFlags,
	__in ACCESS_MASK AccessMode,
	__in ULONG VirtualBytesPerBlock,
	__in PLARGE_INTEGER VirtualLogicalBlockAddress)
{
	DWORD requiredBytes = sizeof(NDAS_ATA_DEVICE_DESCRIPTOR);
	
	PNDAS_ATA_DEVICE_DESCRIPTOR ndasAtaDeviceDescriptor = 
		static_cast<PNDAS_ATA_DEVICE_DESCRIPTOR>(
			HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, requiredBytes));

	if (NULL == ndasAtaDeviceDescriptor)
	{
		CTRACE(TRACE_LEVEL_ERROR, NDASPORTCTL_GENERAL,
			"Memory allocation failure for %d bytes\n", requiredBytes);
		SetLastError(ERROR_OUTOFMEMORY);
		return NULL;
	}

	PNDAS_LOGICALUNIT_DESCRIPTOR logicalUnitDescriptor = 
		&ndasAtaDeviceDescriptor->Header;

	logicalUnitDescriptor->Version = sizeof(NDAS_LOGICALUNIT_DESCRIPTOR);
	logicalUnitDescriptor->Size = requiredBytes;
	logicalUnitDescriptor->Address = LogicalUnitAddress;
	logicalUnitDescriptor->Type = NdasAtaDevice;
	logicalUnitDescriptor->Flags = LogicalUnitFlags;

	ndasAtaDeviceDescriptor->NdasDeviceId = *DeviceIdentifier;
	ndasAtaDeviceDescriptor->NdasDeviceFlagMask = NdasDeviceFlagMask;
	ndasAtaDeviceDescriptor->NdasDeviceFlags = NdasDeviceFlags;
	ndasAtaDeviceDescriptor->AccessMode = AccessMode;

	const BYTE NDAS_DEVICE_PASSWORD_ANY[8] = { 
			0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

	CopyMemory(
		ndasAtaDeviceDescriptor->DevicePassword,
		NDAS_DEVICE_PASSWORD_ANY,
		sizeof(ndasAtaDeviceDescriptor->DevicePassword));

	C_ASSERT(
		sizeof(NDAS_DEVICE_PASSWORD_ANY) == 
		sizeof(ndasAtaDeviceDescriptor->DevicePassword));

	ndasAtaDeviceDescriptor->VirtualBytesPerBlock = VirtualBytesPerBlock;
	ndasAtaDeviceDescriptor->VirtualLogicalBlockAddress = *VirtualLogicalBlockAddress;

	return logicalUnitDescriptor;
}
Esempio n. 24
0
/*Must use real pins*/
SAT_returnState power_control_api(FM_dev_id did, FM_fun_id fid, uint8_t *state) {

    if(!C_ASSERT(did == SYS_DBG) == true)                             { return SATR_ERROR; }
    if(!C_ASSERT(fid == P_OFF || fid == P_ON || fid == P_RESET || fid == SET_VAL) == true)    { return SATR_ERROR; }

    if(did == ADCS_SD_DEV_ID && fid == P_ON)         { } //HAL_adcs_SD_ON(); }
    else if(did == ADCS_SD_DEV_ID && fid == P_OFF)   { }//HAL_adcs_SD_OFF(); }
    else if(did == ADCS_SD_DEV_ID && fid == P_RESET) {
        //HAL_adcs_SD_OFF();
        HAL_sys_delay(60);
        //HAL_adcs_SD_ON();
    }
    else if(did == SYS_DBG && fid == SET_VAL)    {
      //FIXME
    }

    return SATR_OK;
}
// Helper method for updating an interface dispatch indirection cell's stub and cache pointer atomically.
// Returns the value of the cache pointer that is not referenced by the cell after this operation. This can be
// NULL on the initial cell update, the value of the old cache pointer or the value of the new cache pointer
// supplied (in the case where another thread raced with us for the update and won). In any case, if the
// returned pointer is non-NULL it represents a cache that should be scheduled for release.
static InterfaceDispatchCache * UpdateCellStubAndCache(InterfaceDispatchCell * pCell,
                                                       void * pStub,
                                                       UIntNative newCacheValue)
{
    C_ASSERT(offsetof(InterfaceDispatchCell, m_pStub) == 0);
    C_ASSERT(offsetof(InterfaceDispatchCell, m_pCache) == sizeof(void*));

    UIntNative oldCacheValue = (UIntNative)UpdatePointerPairAtomically(pCell, pStub, (void*)newCacheValue, false);

    if (InterfaceDispatchCell::IsCache(oldCacheValue))
    {
        return (InterfaceDispatchCache *)oldCacheValue;
    }
    else
    {
        return nullptr;
    }
}
Esempio n. 26
0
 template < typename _T_REG_UNION > __forceinline void readRegisterNoFence (
     _Out_ _T_REG_UNION* RegUnionPtr
     ) const throw ()
 {
     C_ASSERT(sizeof(UINT32) == sizeof(ULONG));
     ULONG* const regPtr = reinterpret_cast<ULONG*>(
         ULONG_PTR(this->basePtr) + ULONG(RegUnionPtr->OFFSET));
     RegUnionPtr->AsUint32 = ::READ_REGISTER_NOFENCE_ULONG(regPtr);
  } // readRegisterNoFence<...> ( _T_REG_UNION* )
Esempio n. 27
0
PmReturn_t
obj_loadFromImgObj(pPmObj_t pimg, pPmObj_t *r_pobj)
{
    uint8_t const *imgaddr;
    PmReturn_t retval;

    C_ASSERT(OBJ_GET_TYPE(pimg) == OBJ_TYPE_CIO);
    imgaddr = (uint8_t const *)&(((pPmCodeImgObj_t)pimg)->val);

    retval = obj_loadFromImg(MEMSPACE_RAM, &imgaddr, r_pobj);
    C_ASSERT(OBJ_GET_TYPE(*r_pobj) == OBJ_TYPE_COB);

    /* All COs must reference the top of the code img obj 
     * so the image is marked and prevented from being reclaimed */
    co_rSetCodeImgAddr((pPmCo_t)*r_pobj, (uint8_t const *)pimg);

    return retval;
}
Esempio n. 28
0
//used for DMA
SAT_returnState HLDLC_frame(uint8_t *buf_in, uint8_t *buf_out, uint16_t *size) {

    if(!C_ASSERT(buf_in != NULL && buf_out != NULL && size != NULL) == true) { return SATR_ERROR; }
    if(!C_ASSERT(*size <= MAX_PKT_SIZE) == true)                      { return SATR_ERROR; }

    uint16_t cnt = 2;

    for(uint16_t i = 0; i < *size; i++) {
        if(i == 0) {
            buf_out[0] = HLDLC_START_FLAG;
            buf_out[1] = buf_in[0];
        } else if(i == (*size) - 1) {
            if(buf_in[i] == HLDLC_START_FLAG) {
                buf_out[cnt++] = HLDLC_CONTROL_FLAG;
                buf_out[cnt++] = 0x5E;
            } else if(buf_in[i] == HLDLC_STOP_FLAG) {
                buf_out[cnt++] = HLDLC_CONTROL_FLAG;
                buf_out[cnt++] = 0x5C;
            } else if(buf_in[i] == HLDLC_CONTROL_FLAG) {
                buf_out[cnt++] = HLDLC_CONTROL_FLAG;
                buf_out[cnt++] = 0x5D;
            } else {
                buf_out[cnt++] = buf_in[i];
            }
            buf_out[cnt++] = HLDLC_STOP_FLAG;
            *size = cnt;
            return SATR_EOT;
        } else if(buf_in[i] == HLDLC_START_FLAG) {
            buf_out[cnt++] = HLDLC_CONTROL_FLAG;
            buf_out[cnt++] = 0x5E;
        } else if(buf_in[i] == HLDLC_STOP_FLAG) {
            buf_out[cnt++] = HLDLC_CONTROL_FLAG;
            buf_out[cnt++] = 0x5C;
        } else if(buf_in[i] == HLDLC_CONTROL_FLAG) {
            buf_out[cnt++] = HLDLC_CONTROL_FLAG;
            buf_out[cnt++] = 0x5D;
        } else {
            buf_out[cnt++] = buf_in[i];
        }

    }

    return SATR_ERROR;
}
Esempio n. 29
0
/*Must use real pins*/
SAT_returnState power_control_api(FM_dev_id did, FM_fun_id fid, uint8_t *state) {

    if(!C_ASSERT(did == COMMS_WOD_PAT || did == SYS_DBG) == true) {
      return SATR_ERROR;
    }
    if (!C_ASSERT(fid == P_OFF || fid == P_ON || fid == P_RESET
		  || fid == SET_VAL) == true) {
      return SATR_ERROR;
    }

    if (did == COMMS_WOD_PAT && fid == SET_VAL) {
      comms_write_persistent_word(state[0],
				  __COMMS_HEADLESS_TX_FLASH_OFFSET);
    }
    else if(did == SYS_DBG && fid == SET_VAL)    {
      //FIXME
    }

    return SATR_OK;
}
SAT_returnState hk_crt_pkt_TC(tc_tm_pkt *pkt, const TC_TM_app_id app_id, const HK_struct_id sid) {

    if(!C_ASSERT(app_id < LAST_APP_ID) == true)  { return SATR_ERROR; }

    crt_pkt(pkt, app_id, TC, TC_ACK_NO, TC_HOUSEKEEPING_SERVICE, TC_HK_REPORT_PARAMETERS, (TC_TM_app_id)SYSTEM_APP_ID);

    pkt->data[0] = (char)sid;
    pkt->len = 1;

    return SATR_OK;
}