/** Convert the IKE Header from Host order to Network order. @param[in, out] Header The pointer of the IKE_HEADER. **/ VOID IkeHdrHostToNet ( IN OUT IKE_HEADER *Header ) { Header->InitiatorCookie = HTONLL (Header->InitiatorCookie); Header->ResponderCookie = HTONLL (Header->ResponderCookie); Header->MessageId = HTONL (Header->MessageId); Header->Length = HTONL (Header->Length); }
BOOL VendorGetLock11( IN PRAM_DATA RamData, IN PLANSCSI_VENDOR_REQUEST_PDU_HEADER RequestHeader, OUT PLANSCSI_VENDOR_REPLY_PDU_HEADER ReplyHeader ){ UINT64 vendorParam; UCHAR lockNo; PGENERAL_PURPOSE_LOCK gpLock; DWORD dwWaitResult; vendorParam = NTOHLL(RequestHeader->VendorParameter); lockNo = (UCHAR)((vendorParam>>32) & 0x3); gpLock = &RamData->GPLocks[lockNo]; // // Acquire the mutex for the lock access // dwWaitResult = WaitForSingleObject(RamData->LockMutex, INFINITE); if(dwWaitResult != WAIT_OBJECT_0) return FALSE; // // Set return counter // ReplyHeader->VendorParameter = HTONLL((UINT64)gpLock->Counter); ReleaseMutex(RamData->LockMutex); return TRUE; }
int net_if_get_eui64(net_if_eui64_t *eui64, int if_id, int force_generation) { uint64_t tmp; if (if_id < 0 || if_id >= NET_IF_MAX || !interfaces[if_id].initialized) { DEBUG("Get EUI-64: No interface initialized with ID %d.\n", if_id); return 0; } if (eui64 == NULL) { DEBUG("Get EUI-64: parameter eui64 is a NULL pointer.\n"); return 0; } net_if_transceiver_get_set_handler(if_id, GET_LONG_ADDR, &tmp); eui64->uint64 = HTONLL(tmp); if (eui64->uint64 == 0 || force_generation) { uint16_t hwaddr = net_if_get_hardware_address(if_id); if (hwaddr == 0) { return 0; } /* RFC 6282 Section 3.2.2 / RFC 2464 Section 4 */ /* Since this is a short address, which is never globally unique, we set * the local/universal bit to 1. */ eui64->uint32[0] = HTONL(0x020000ff); eui64->uint16[2] = HTONS(0xfe00); eui64->uint16[3] = HTONS(hwaddr); } return 1; }
/* Get the long long in the correct byte order */ static long long byteSwapLongLong(PBYTE_BUFFER buff, long long l) { if (buff->byteOrder == BYTE_ORDER_BIG) { return HTONLL(l); } else { return l; } }
BOOL VendorFreeLock11( IN PRAM_DATA RamData, IN UINT64 SessionId, IN PLANSCSI_VENDOR_REQUEST_PDU_HEADER RequestHeader, OUT PLANSCSI_VENDOR_REPLY_PDU_HEADER ReplyHeader ){ UINT64 vendorParam; UCHAR lockNo; PGENERAL_PURPOSE_LOCK gpLock; LONG acquired; DWORD dwWaitResult; vendorParam = NTOHLL(RequestHeader->VendorParameter); lockNo = (UCHAR)((vendorParam>>32) & 0x3); gpLock = &RamData->GPLocks[lockNo]; // fprintf(stderr, "VendorSetLock11: freeing lock %d.\n", lockNo); // // Acquire the mutex for the lock access // dwWaitResult = WaitForSingleObject(RamData->LockMutex, INFINITE); if(dwWaitResult != WAIT_OBJECT_0) return FALSE; // // Set return counter // ReplyHeader->VendorParameter = HTONLL((UINT64)gpLock->Counter); if(SessionId == gpLock->SessionId) { if(gpLock->Acquired == FALSE) { fprintf(stderr, "VendorFreeLock11: Already freed\n"); } else { gpLock->Acquired = FALSE; // fprintf(stderr, "VendorSetLock11: lock %d freed.\n", lockNo); } } else { // // Not owner // ReleaseMutex(RamData->LockMutex); fprintf(stderr, "VendorFreeLock11: Not lock owner!\n"); ReplyHeader->Response = LANSCSI_RESPONSE_T_COMMAND_FAILED; return TRUE; } ReleaseMutex(RamData->LockMutex); return TRUE; }
BOOLEAN XixFsIHaveLotLock( IN uint8 * HostMac, IN uint64 LotNumber, IN uint8 * DiskId, IN uint32 PartitionId ) { NTSTATUS RC = STATUS_UNSUCCESSFUL; PXIFSDG_PKT pPacket = NULL; PXIFS_LOCK_BROADCAST pPacketData = NULL; uint8 DstAddress[6] ={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; //PAGED_CODE(); DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Enter XixFsIHaveLotLock \n")); // Changed by ILGU HONG // chesung suggest /* if(FALSE ==LfsAllocDGPkt(&pPacket, HostMac, DstAddress, XIFS_TYPE_LOCK_BROADCAST)) { return FALSE; } */ if(FALSE ==LfsAllocDGPkt(&pPacket, HostMac, NULL, XIFS_TYPE_LOCK_BROADCAST)) { return FALSE; } pPacketData = &(pPacket->RawDataDG.LockBroadcast); // Changed by ILGU HONG //RtlCopyMemory(pPacketData->DiskId, DiskId, 6); RtlCopyMemory(pPacketData->DiskId, DiskId, 16); pPacketData->PartionId = HTONL(PartitionId); pPacketData->LotNumber = HTONLL(LotNumber); pPacket->TimeOut.QuadPart = XixGetSystemTime().QuadPart + DEFAULT_REQUEST_MAX_TIMEOUT; ExAcquireFastMutex(&XiGlobalData.XifsComCtx.SendPktListMutex); InsertTailList(&(XiGlobalData.XifsComCtx.SendPktList), &(pPacket->PktListEntry) ); ExReleaseFastMutex(&XiGlobalData.XifsComCtx.SendPktListMutex); KeSetEvent(&(XiGlobalData.XifsComCtx.CliSendDataEvent),0, FALSE); DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XixFsIHaveLotLock \n")); return TRUE; }
BOOL VendorSetLock11( IN PRAM_DATA_OLD RamData, IN UINT64 SessionId, IN PLANSCSI_VENDOR_REQUEST_PDU_HEADER RequestHeader, OUT PLANSCSI_VENDOR_REPLY_PDU_HEADER ReplyHeader ){ UINT64 vendorParam; UCHAR lockNo; PGENERAL_PURPOSE_LOCK gpLock; LONG acquired; DWORD dwWaitResult; vendorParam = NTOHLL(RequestHeader->VendorParameter); lockNo = (UCHAR)((vendorParam>>32) & 0x3); gpLock = &RamData->GPLocks[lockNo]; fprintf(stderr, "VendorSetLock11: Acquiring lock %d.\n", lockNo); // // Acquire the mutex for the lock access // dwWaitResult = WaitForSingleObject(RamData->LockMutex, INFINITE); if(dwWaitResult != WAIT_OBJECT_0) return FALSE; if(gpLock->Acquired == FALSE) { // // GP lock acquired // gpLock->Acquired = TRUE; gpLock->Counter ++; gpLock->SessionId = SessionId; // // Set return counter // ReplyHeader->VendorParameter = HTONLL((UINT64)gpLock->Counter); fprintf(stderr, "VendorSetLock11: lock %d acquired(%ld).\n", lockNo, gpLock->SessionId); // // GP lock Already acquired by others // } else { // // Set return counter // ReplyHeader->VendorParameter = HTONLL((UINT64)gpLock->Counter); ReleaseMutex(RamData->LockMutex); fprintf(stderr, "VendorSetLock11: Lock contention!\n"); ReplyHeader->Response = LANSCSI_RESPONSE_T_SET_SEMA_FAIL; return TRUE; } ReleaseMutex(RamData->LockMutex); return TRUE; }
jobject buildDataRecord(ipfix_datarecord_t *d, ipfixt_node_t *t) { jclass cObject = (*senv)->FindClass(senv, "java/lang/Object"); int nfields = t->ipfixt->nfields; jobjectArray addrs = (*senv)->NewObjectArray(senv, nfields, cObject, NULL); int i; for (i=0; i<nfields; i++) { int len = d->lens[i]; int coding = t->ipfixt->fields[i].elem->ft->coding; jobject record; jbyteArray value = (*senv)->NewByteArray(senv, len); (*senv)->SetByteArrayRegion(senv, value, 0, len, d->addrs[i]); switch (coding) { case IPFIX_CODING_INT: case IPFIX_CODING_NTP: //todo: convert into java/util/Timestamp case IPFIX_CODING_UINT: { //todo: make unsigned (increase [B len by 1?) jclass cBigInteger = (*senv)->FindClass(senv, "java/math/BigInteger"); jmethodID mCon = (*senv)->GetMethodID(senv, cBigInteger, "<init>", "([B)V"); record = (*senv)->NewObject(senv, cBigInteger, mCon, value); break; } case IPFIX_CODING_IPADDR: { jclass cInetAddress = (*senv)->FindClass(senv, "java/net/InetAddress"); jmethodID mCon = (*senv)->GetStaticMethodID(senv, cInetAddress, "getByAddress", "([B)Ljava/net/InetAddress;"); record = (*senv)->CallStaticObjectMethod(senv, cInetAddress, mCon, value); break; } case IPFIX_CODING_STRING: { jclass cString = (*senv)->FindClass(senv, "java/lang/String"); jmethodID mCon = (*senv)->GetMethodID(senv, cString, "<init>", "([B)V"); record = (*senv)->NewObject(senv, cString, mCon, value); break; } case IPFIX_CODING_FLOAT: { uint32_t tmp32; uint64_t tmp64; float tmpfloat; double tmpdouble; switch ( len ) { case 4: memcpy( &tmp32, d->addrs[i], 8); tmp32 = htonl( tmp32); memcpy( &tmpfloat, &tmp32, 8); jclass cFloat = (*senv)->FindClass(senv, "java/lang/Float"); jmethodID mCon = (*senv)->GetMethodID(senv, cFloat, "<init>", "(F)V"); record = (*senv)->NewObject(senv, cFloat, mCon, tmpfloat); case 8: { memcpy( &tmp64, d->addrs[i], 8); tmp64 = HTONLL( tmp64); memcpy( &tmpdouble, &tmp64, 8); jclass cDouble = (*senv)->FindClass(senv, "java/lang/Double"); jmethodID mCon = (*senv)->GetMethodID(senv, cDouble, "<init>", "(D)V"); record = (*senv)->NewObject(senv, cDouble, mCon, tmpdouble); } } // jclass cBigDecimal = (*senv)->FindClass(senv, "java/math/BigDecimal"); // jmethodID mCon = (*senv)->GetMethodID(senv, cBigDecimal, "<init>", "([B)V"); // record = (*senv)->NewObject(senv, cBigDecimal, mCon, value); break; } case IPFIX_CODING_BYTES: default: { record = value; break; } } (*senv)->SetObjectArrayElement(senv, addrs, i, record); } jint maxfields = d->maxfields; jclass cDR = (*senv)->FindClass(senv, "de/fraunhofer/fokus/ants/jipfix/data/IPFIXDataRecord"); jmethodID mCon = (*senv)->GetMethodID(senv, cDR, "<init>", "([Ljava/lang/Object;I)V"); jobject oDR = (*senv)->NewObject(senv, cDR, mCon, addrs, maxfields); return oDR; }
/** Print the IKE Packet. @param[in] Packet Point to IKE packet to be printed. @param[in] Direction Point to the IKE packet is inbound or outbound. @param[in] IpVersion Specified IP Version. **/ VOID IpSecDumpPacket ( IN IKE_PACKET *Packet, IN EFI_IPSEC_TRAFFIC_DIR Direction, IN UINT8 IpVersion ) { CHAR8 *TypeStr; UINTN PacketSize; UINT64 InitCookie; UINT64 RespCookie; ASSERT (Packet != NULL); PacketSize = Packet->PayloadTotalSize + sizeof (IKE_HEADER); InitCookie = (Direction == EfiIPsecOutBound) ? HTONLL (Packet->Header->InitiatorCookie) : Packet->Header->InitiatorCookie; RespCookie = (Direction == EfiIPsecOutBound) ? HTONLL (Packet->Header->ResponderCookie) : Packet->Header->ResponderCookie; switch (Packet->Header->ExchangeType) { case IKE_XCG_TYPE_IDENTITY_PROTECT: TypeStr = mExchangeStr[0]; break; case IKE_XCG_TYPE_INFO: TypeStr = mExchangeStr[1]; break; case IKE_XCG_TYPE_QM: TypeStr = mExchangeStr[2]; break; case IKE_XCG_TYPE_SA_INIT: TypeStr = mExchangeStr[3]; break; case IKE_XCG_TYPE_AUTH: TypeStr = mExchangeStr[4]; break; case IKE_XCG_TYPE_CREATE_CHILD_SA: TypeStr = mExchangeStr[5]; break; case IKE_XCG_TYPE_INFO2: TypeStr = mExchangeStr[6]; break; default: TypeStr = mExchangeStr[7]; break; } if (Direction == EfiIPsecOutBound) { DEBUG ((DEBUG_INFO, "\n>>>Sending %d bytes %a to ", PacketSize, TypeStr)); } else { DEBUG ((DEBUG_INFO, "\n>>>Receiving %d bytes %a from ", PacketSize, TypeStr)); } IpSecDumpAddress (DEBUG_INFO, &Packet->RemotePeerIp, IpVersion); DEBUG ((DEBUG_INFO, " InitiatorCookie:0x%lx ResponderCookie:0x%lx\n", InitCookie, RespCookie)); DEBUG ( (DEBUG_INFO, " Version: 0x%x Flags:0x%x ExchangeType:0x%x\n", Packet->Header->Version, Packet->Header->Flags, Packet->Header->ExchangeType) ); DEBUG ( (DEBUG_INFO, " MessageId:0x%x NextPayload:0x%x\n", Packet->Header->MessageId, Packet->Header->NextPayload) ); }
BOOLEAN XixFsAreYouHaveLotLock( IN BOOLEAN Wait, IN uint8 * HostMac, IN uint8 * LockOwnerMac, IN uint64 LotNumber, IN uint8 * DiskId, IN uint32 PartitionId, IN uint8 * LockOwnerId ) { // Request LotLock state to Lock Owner NTSTATUS RC = STATUS_UNSUCCESSFUL; PXIFSDG_PKT pPacket = NULL; PXIFS_LOCK_REQUEST pPacketData = NULL; XIFS_LOCK_CONTROL LockControl; //PAGED_CODE(); DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Enter XixFsAreYouHaveLotLock \n")); ASSERT(Wait); if(FALSE ==LfsAllocDGPkt(&pPacket, HostMac, LockOwnerMac, XIFS_TYPE_LOCK_REQUEST)) { return FALSE; } // Changed by ILGU HONG // chesung suggest /* DebugTrace(DEBUG_LEVEL_INFO, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Packet Dest Info [0x%02x:%02x:%02x:%02x:%02x:%02x]\n", LockOwnerMac[0], LockOwnerMac[1], LockOwnerMac[2], LockOwnerMac[3], LockOwnerMac[4], LockOwnerMac[5])); */ DebugTrace(DEBUG_LEVEL_INFO, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Packet Dest Info [0x%02x:%02x:%02x:%02x:%02x:%02x]\n", LockOwnerMac[26], LockOwnerMac[27], LockOwnerMac[28], LockOwnerMac[29], LockOwnerMac[30], LockOwnerMac[31])); pPacketData = &(pPacket->RawDataDG.LockReq); RtlCopyMemory(pPacketData->LotOwnerID, LockOwnerId, 16); // Changed by ILGU HONG // chesung suggest //RtlCopyMemory(pPacketData->DiskId, DiskId, 6); //RtlCopyMemory(pPacketData->LotOwnerMac, LockOwnerMac, 6); RtlCopyMemory(pPacketData->DiskId, DiskId, 16); RtlCopyMemory(pPacketData->LotOwnerMac, LockOwnerMac, 32); pPacketData->PartionId = HTONL(PartitionId); pPacketData->LotNumber = HTONLL(LotNumber); pPacketData->PacketNumber = HTONL(XiGlobalData.XifsComCtx.PacketNumber); XiGlobalData.XifsComCtx.PacketNumber++; pPacket->TimeOut.QuadPart = XixGetSystemTime().QuadPart + DEFAULT_REQUEST_MAX_TIMEOUT; KeInitializeEvent(&LockControl.KEvent, SynchronizationEvent, FALSE); LockControl.Status = LOCK_INVALID; pPacket->pLockContext = &LockControl; ExAcquireFastMutex(&XiGlobalData.XifsComCtx.SendPktListMutex); InsertTailList(&(XiGlobalData.XifsComCtx.SendPktList), &(pPacket->PktListEntry) ); ExReleaseFastMutex(&XiGlobalData.XifsComCtx.SendPktListMutex); KeSetEvent(&(XiGlobalData.XifsComCtx.CliSendDataEvent),0, FALSE); RC = KeWaitForSingleObject(&LockControl.KEvent, Executive, KernelMode, FALSE, NULL); if(!NT_SUCCESS(RC)){ DebugTrace(DEBUG_LEVEL_CRITICAL, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XixFsAreYouHaveLotLock \n")); return FALSE; } if(LockControl.Status == LOCK_OWNED_BY_OWNER){ DebugTrace(DEBUG_LEVEL_CRITICAL, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XixFsAreYouHaveLotLock Lock is realy acquired by other \n")); return TRUE; } DebugTrace(DEBUG_LEVEL_CRITICAL, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XifsdAreYouHaveLotLock Lock is status(0x%x) \n", LockControl.Status)); /* TRUE --> Lock is Owner by Me FALSE --> Lock is Not Mine FALSE--> TimeOut Lock Owner is not in Network */ DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XifsdAreYouHaveLotLock \n")); return FALSE; }
NTSTATUS XixFsdSendFileChangeRC( IN BOOLEAN Wait, IN uint8 * HostMac, IN uint64 LotNumber, IN uint8 * DiskId, IN uint32 PartitionId, IN uint64 FileLength, IN uint64 AllocationLength, IN uint64 UpdateStartOffset ) { NTSTATUS RC = STATUS_UNSUCCESSFUL; PXIFSDG_PKT pPacket = NULL; PXIFS_FILE_LENGTH_CHANGE_BROADCAST pPacketData = NULL; uint8 DstAddress[6] ={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Enter XixFsdSendFileChangeRC \n")); ASSERT(Wait); // Changed by ILGU HONG // chesung suggest /* if(FALSE ==LfsAllocDGPkt(&pPacket, HostMac, DstAddress, XIFS_TYPE_FILE_LENGTH_CHANGE)) { return FALSE; } */ if(FALSE ==LfsAllocDGPkt(&pPacket, HostMac, DstAddress, XIFS_TYPE_FILE_LENGTH_CHANGE)) { return FALSE; } pPacketData = &(pPacket->RawDataDG.FileLenChangeReq); // Changed by ILGU HONG // RtlCopyMemory(pPacketData->DiskId, DiskId, 6); RtlCopyMemory(pPacketData->DiskId, DiskId, 16); pPacketData->PartionId = HTONL(PartitionId); pPacketData->LotNumber = HTONLL(LotNumber); pPacketData->FileLength = HTONLL(FileLength); pPacketData->AllocationLength = HTONLL(AllocationLength); pPacketData->WriteStartOffset = HTONLL(UpdateStartOffset); pPacket->TimeOut.QuadPart = XixGetSystemTime().QuadPart + DEFAULT_REQUEST_MAX_TIMEOUT; ExAcquireFastMutex(&XiGlobalData.XifsComCtx.SendPktListMutex); InsertTailList(&(XiGlobalData.XifsComCtx.SendPktList), &(pPacket->PktListEntry) ); ExReleaseFastMutex(&XiGlobalData.XifsComCtx.SendPktListMutex); KeSetEvent(&(XiGlobalData.XifsComCtx.CliSendDataEvent),0, FALSE); DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XixFsdSendFileChangeRC \n")); return STATUS_SUCCESS; }
NTSTATUS xixfs_SendRenameLinkBC( IN BOOLEAN Wait, IN uint32 SubCommand, IN uint8 * HostMac, IN uint64 LotNumber, IN uint8 * VolumeId, IN uint64 OldParentLotNumber, IN uint64 NewParentLotNumber ) { NTSTATUS RC = STATUS_UNSUCCESSFUL; PXIXFSDG_PKT pPacket = NULL; PXIXFS_FILE_CHANGE_BROADCAST pPacketData = NULL; XIFS_LOCK_CONTROL LockControl; uint8 DstAddress[6] ={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Enter XifsdSendRenameLinkBC \n")); ASSERT(Wait); // Changed by ILGU HONG // chesung suggest /* if(FALSE ==xixfs_AllocDGPkt(&pPacket, HostMac, DstAddress, XIXFS_TYPE_FILE_CHANGE)) { return FALSE; } */ if(FALSE ==xixfs_AllocDGPkt(&pPacket, HostMac, NULL, XIXFS_TYPE_FILE_CHANGE)) { return FALSE; } pPacketData = &(pPacket->RawDataDG.FileChangeReq); // Changed by ILGU HONG RtlCopyMemory(pPacketData->VolumeId, VolumeId, 16); pPacketData->LotNumber = HTONLL(LotNumber); pPacketData->PrevParentLotNumber = HTONLL(OldParentLotNumber); pPacketData->NewParentLotNumber = HTONLL(NewParentLotNumber); pPacketData->SubCommand =HTONL(SubCommand); pPacket->TimeOut.QuadPart = xixcore_GetCurrentTime64() + DEFAULT_REQUEST_MAX_TIMEOUT; ExAcquireFastMutexUnsafe(&XiGlobalData.XifsComCtx.SendPktListMutex); InsertTailList(&(XiGlobalData.XifsComCtx.SendPktList), &(pPacket->PktListEntry) ); ExReleaseFastMutexUnsafe(&XiGlobalData.XifsComCtx.SendPktListMutex); KeSetEvent(&(XiGlobalData.XifsComCtx.CliSendDataEvent),0, FALSE); DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_RESOURCE| DEBUG_TARGET_FCB|DEBUG_TARGET_LOCK), ("Exit XifsdSendRenameLinkBC \n")); return STATUS_SUCCESS; }