// // Claim // // Claim and 2D and 3D voices using the given providers // void Claim(HDIGDRIVER *h2D, U32 max2D, HPROVIDER *h3D, U32 max3D) { LOG_DIAG(("Output::Claim:")); // Do we have a 2D digital audio service if (h2D) { // Allocate the 2D voices U32 v = 0; for (; v < max2D && totalVoices < MAX_VOICES; v++) { // Allocate a new voice handle if (HSAMPLE vHandle = AIL_allocate_sample_handle(*h2D)) { // Allocate a new 2D voice voices[totalVoices++] = new Voice(vHandle); } else { // No more voices to allocate break; } } LOG_DIAG((" - Allocated %d 2D voices", v)); } else { LOG_DIAG((" - No 2D digital audio services")); } // Do we have a 3D digital audio service if (h3D) { // Allocate the 3D voices U32 v = 0; for (; v < max3D && totalVoices < MAX_VOICES; v++) { // Allocate a new voice handle H3DSAMPLE vHandle = AIL_allocate_3D_sample_handle(*h3D); if (vHandle) { // Allocate a new 3D voice voices[totalVoices++] = new Voice(vHandle); } else { // No more voices to allocate break; } } LOG_DIAG((" - Allocated %d 3D voices", v)); } else { LOG_DIAG((" - No 3D digital audio services")); } }
U32 Mesh::Manager::Report() { U32 countT = 0, memT = 0; NBinTree<MeshRoot>::Iterator ri(&rootTree); while (MeshRoot * root = ri++) { if (!root->isChunk) { memT += root->GetMem(); countT++; } } U32 countE = 0, memE = 0; NList<MeshEnt>::Iterator ei(&entList); while (MeshEnt * ent = ei++) { memE += ent->GetMem(); countE++; } U32 mem = memT + memE + endVar - startVar; // namespace CON_DIAG( ("%4d %-31s: %9d", countT, "mesh types", memT ) ); LOG_DIAG( ("%4d %-31s: %9d", countT, "mesh types", memT ) ); CON_DIAG( ("%4d %-31s: %9d", countE, "mesh instances", memE ) ); LOG_DIAG( ("%4d %-31s: %9d", countE, "mesh instances", memE ) ); return mem; }
// // Claim // // Claim a redbook driver // Bool Claim() { if (initialized) { int drive; // Release any current driver Release(); // First, try and find the specified volume if (*volumeLabel && Drive::FindDriveByVolume(Drive::CDROM, volumeLabel, drive)) { if ((driver = AIL_redbook_open_drive(char(drive + 'A'))) != NULL) { LOG_DIAG(("Redbook::Claim - Success by volume [%s]", volumeLabel)); } } // Second, try and find an audio cd (for custom cd in second drive) if (!driver && Drive::FindDriveByVolume(Drive::CDROM, "Audio CD", drive)) { if ((driver = AIL_redbook_open_drive(char(drive + 'A'))) != NULL) { LOG_DIAG(("Redbook::Claim - Success on Audio CD")); } } // Third, just grab the first device if (!driver) { for (S32 i = 0; i < MAX_DEVICES; i++) { if ((driver = AIL_redbook_open(i)) != NULL) { LOG_DIAG(("Redbook::Claim - Success on first available [%d]", i)); break; } } } if (driver) { // Stop the cd playing anything Stop(); return (TRUE); } LOG_DIAG(("Redbook::Claim - Failed")); } return (FALSE); }
// // DTrack::DebugDestruction // // Debug routine called on destruction // void DTrack::DebugDestruction() { // Do some debugging checks U32 count = 0; // Scan each block for (NList<Block>::Iterator b(&blocks); *b; b++) { // Check each item for (U32 i = 0; i < blockSize; i++) { if ((*b)->data[i] != DTRACK_EMPTY) { count++; } } } // Show diag if any items still registered if (count) { LOG_DIAG(("DTrack '%s' still had %d/%d registered items at shutdown", name.str, count, stateInfo.items)); } // Log some performance diagnostics /* LOG_DIAG (( "DTrack %s c%d/%d b%d max%d i%d mem%d", name.str, stateInfo.cacheHits, stateInfo.cacheMisses, blocks.GetCount(), stateInfo.maxItems, idCount, (blocks.GetCount() * blockSize * sizeof(U32)) + (cacheSize * sizeof(U32*)) )); */ }
void Camera::CreateOcclusion() { if (Occlusion) { return ; } Occlusion = new OcclusionClass(this); #if 0 //now that everything is initilize try to create the occlusion camera Camera *OcclusionCam = NULL; try { // Attent to create a harware occlusion camera OcclusionCam = new CameraOcclusionHardware( "occlusion"); } catch (char *Message) { LOG_DIAG( (Message) ); // No hardware occlusion support create a software emulation // occlusion OcclusionCam = new CameraOcclusion( "occlusion"); if (!OcclusionCam) { ERR_FATAL( ("can't create OcclusionCamera") ); } } #endif }
// // Notify this task of an event // Bool SquadMoveTogether::ProcessEvent(const Event &event) { switch (event.message) { case GameObjNotify::Interrupted: LOG_DIAG(("SquadMoveTogether: Interrupted")) inst.Set(0xABAA7B48); // "Init" return (TRUE); case 0x6B0DB5AA: // "Move::Incapable" { // One of the units in the squad is telling us // it can't make it to the destination // LOG_DIAG(("Unit %d in the squad could not make it to its destination", event.param2)) for (SquadObj::UnitList::Iterator i(&subject->GetList()); *i; i++) { if ( (*i)->Alive() && (*i)->task == event.param1 && (*i)->Id() == event.param2) { (*i)->completed = TRUE; GoToNextPoint(*i); } } return (TRUE); } case 0xFCBF8881: // "Move::Completed" { // One of the units in the squad is telling us // it made it to the destination // LOG_DIAG(("Unit %d in the squad made it to its destination", event.param2)) // Mark the completed flag for this squad member for (SquadObj::UnitList::Iterator i(&subject->GetList()); *i; i++) { if ( (*i)->Alive() && (*i)->task == event.param1 && (*i)->Id() == event.param2) { (*i)->completed = TRUE; if ((*i)->data < point || TestState(0x9E947215)) // "Moving" { // LOG_DIAG(("We're in the move state so proceeding immediately")) GoToNextPoint(*i); } break; } } return (TRUE); } default: return (GameTask<SquadObjType, SquadObj>::ProcessEvent(event)); } }
U32 Mesh::Manager::ReportList( const char * name) // = NULL { U32 count = 0; U32 len = 0, hit = FALSE; if ( name) { len = strlen( name); } else { hit = TRUE; } U32 mem = 0; remem = recount = rgeo = ranim = rmrm = 0; NBinTree<MeshRoot>::Iterator li(&rootTree); while (MeshRoot * root = li++) { if (!root->isChunk && (!name || !strnicmp( root->fileName.str, name, len))) { mem += Report( *root); hit = TRUE; count++; } } if (hit) { CON_DIAG( ("%4ld %-31s: %9ld g%6ld a%6ld m%6ld", count, "mesh types", mem, rgeo, ranim, rmrm )); LOG_DIAG( ("%4ld %-31s: %9ld g%6ld a%6ld m%6ld", count, "mesh types", mem, rgeo, ranim, rmrm )); CON_DIAG( ("%4ld %-31s: %9ld", recount, "mesh instances", remem ) ); LOG_DIAG( ("%4ld %-31s: %9ld", recount, "mesh instances", remem ) ); } else { CON_DIAG( ("Can't find mesh type: %s", name) ); } return mem + remem; }
// // CmdHandler // void CmdHandler(U32 pathCrc) { switch (pathCrc) { case 0x43382C8E: // "sys.game.runcode" { const char *s; if (Console::ArgCount() == 2 && Console::GetArgString(1, s)) { Set(s); } else { CON_ERR((Console::ARGS)) } break; } case 0xBB563A77: // "sys.game.migrate.start" SYNC("Migration commencing") IFace::Activate("|Game::Resync"); migration = MIGRATING; LOG_DIAG(("Switching to MIGRATING")) break; case 0x7CE02766: // "sys.game.migrate.resync" if (migration == MIGRATING) { migration = RESYNC; LOG_DIAG(("Switching to RESYNC")) MultiPlayer::SetReady(); } break; case 0x7D690127: // "sys.game.migrate.end" { SYNC("Migration completed") // Change runcode to the sim IControl *ctrl = IFace::FindByName("|Game::Resync"); if (ctrl) { IFace::SendNotify(ctrl, NULL, 0x334DAB78); // "ResyncComplete" IFace::Deactivate(ctrl); } MultiPlayer::ClearReady(); migration = NORMAL; LOG_DIAG(("Switching to NORMAL")) break; } default: break; } }
/** * Create Link * * @brief Allocate Memory for Link structure and populate using input * parameters * * @post On allocation failure, @a p will be freed if #SAH_OWNS_LINK_DATA is * p set in @a flags. * @param mu Memory functions * @param link Pointer to link to be created * @param p Pointer to data to use in link * @param length Length of buffer 'p' in bytes * @param flags Indicates whether memory has been allocated by the calling * function or the security function * * @return FSL_RETURN_OK_S or FSL_RETURN_NO_RESOURCE_S */ fsl_shw_return_t sah_Create_Link( const sah_Mem_Util *mu, sah_Link **link, uint8_t *p, const size_t length, const sah_Link_Flags flags) { #ifdef DIAG_SECURITY_FUNC_UGLY char diag[50]; #endif /*DIAG_SECURITY_FUNC_UGLY*/ fsl_shw_return_t status = FSL_RETURN_NO_RESOURCE_S; *link = mu->mu_alloc_link(mu->mu_ref); /* populate link if memory allocation successful */ if (*link != NULL) { (*link)->len = length; (*link)->data = p; (*link)->next = NULL; (*link)->flags = flags; status = FSL_RETURN_OK_S; #ifdef DIAG_SECURITY_FUNC_UGLY LOG_DIAG("Created Link"); LOG_DIAG("------------"); sprintf(diag," address = 0x%x", (int) *link); LOG_DIAG(diag); sprintf(diag," link->len = %d",(*link)->len); LOG_DIAG(diag); sprintf(diag," link->data = 0x%x",(int) (*link)->data); LOG_DIAG(diag); sprintf(diag," link->flags = 0x%x",(*link)->flags); LOG_DIAG(diag); LOG_DIAG(" link->next = NULL"); #endif /*DIAG_SECURITY_FUNC_UGLY*/ } else { #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Allocation of memory for sah_Link failed!\n"); #endif /*DIAG_SECURITY_FUNC*/ /* Free memory previously allocated by the security function layer for link data. Note that the memory being pointed to will be zeroed before being freed, for security reasons. */ if (flags & SAH_OWNS_LINK_DATA) { mu->mu_memset(mu->mu_ref, p, 0x00, length); mu->mu_free(mu->mu_ref, p); } } return status; }
// // Init // void Init() { /* // Set the correct video mode if (Vid::isStatus.fullScreen) { Vid::SetMode(Vid::gameMode); } */ // Clear the migration status migration = NORMAL; LOG_DIAG(("Switching to NORMAL")) // Bring the client online Client::Init(); // Tell ai we're starting the sim AI::InitSimulation(); // Process Environment //Environment::Process(); // Perform first rendering of sight //Sight::UpdateDisplay(Team::GetDisplayTeam()); //Terrain::Simulate(GameTime::SimTime()); // MapObjCtrl::SimulateSim(GameTime::SimTime()); MapObjCtrl::UpdateMapPos(); // Do display if (Vid::isStatus.active) { // These need to be done or the initial render gets incorrect values Client::Display::PreRender(); Display( TRUE); // Post Render Vid::RenderEnd(); // Blank out the first frame Vid::ClearBack(); Vid::RenderFlush(); } // If we're in multiplayer, create the synchronizing control if (!MultiPlayer::Data::Online()) { RC::Set("Sim"); } // Notify demo that sim is starting Demo::InitSimulation(); }
// // Done // void Done() { IFace::Deactivate("|Game::Synchronizing"); // If the next runcode isn't Sim then go through the motions of Sim if (runCodes.GetNextCrc() != 0xBE9A9686) // "Sim" { LOG_DIAG(("Leaving SimInit and not going to Sim, cycling Sim::Init & Sim::Done")) Sim::Init(); Sim::Done(); } }
// // RequestPath // // Request a new path be found. Returns FALSE if request is invalid. // Finder::RequestResult Finder::RequestPath ( U32 sx, U32 sz, U32 dx, U32 dz, U8 traction, UnitObj *unit, SearchType type, U32 flags, PointList *blockList ) { // Forget any current path ForgetPath(); // Is destination on the map if (!WorldCtrl::CellOnMap(sx, sz) || !WorldCtrl::CellOnMap(dx, dz)) { LOG_DIAG(("Request position is not on the map (%u, %u)->(%u,%u)", sx, sz, dx, dz)); return (RR_OFFMAP); } // Filter out requests to move to the same cell if (sx == dx && sz == dz) { return (RR_SAMECELL); } // Can this traction type move to this cell if (!CanMoveToCell(traction, dx, dz)) { U32 xNew, zNew; // Find the closest location we can move to if (FindClosestCell(traction, dx, dz, xNew, zNew, 15)) { // Use the new location dx = xNew; dz = zNew; } else // AStar will fail, so jump straight to trace if (type == ST_ASTAR) { type = ST_TRACE; } } // Create a new path path = new Path(sx, sz, dx, dz, traction, unit, type, flags, blockList); // Add to the system AddPath(path); // Success return (RR_SUBMITTED); }
// // RunCodes::Clear // void RunCodes::Clear() { // Initialize the new run code LOG_DIAG(("[%s] Clearing runcode [%s]", ident.str, currentRC ? currentRC->ident.str : "<NONE>")); // Shutdown the current run code if (currentRC && currentRC->fnDone) { currentRC->fnDone(); } // Clear the current runcode currentRC = NULL; }
fsl_shw_return_t fsl_shw_read_key(fsl_shw_uco_t * user_ctx, fsl_shw_sko_t * key_info, uint8_t * key) { fsl_shw_return_t ret = FSL_RETURN_INTERNAL_ERROR_S; /* Only blocking mode calls are supported */ if (!(user_ctx->flags & FSL_UCO_BLOCKING_MODE)) { ret = FSL_RETURN_BAD_FLAG_S; goto out; } printk("Reading a key\n"); #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Reading a key"); #endif if (key_info->flags & FSL_SKO_KEY_PRESENT) { memcpy(key_info->key, key, key_info->key_length); ret = FSL_RETURN_OK_S; } else if (key_info->flags & FSL_SKO_KEY_ESTABLISHED) { printk("key established\n"); if (key_info->keystore == NULL) { printk("keystore is null\n"); /* First verify that the key access is valid */ ret = system_keystore.slot_verify_access(system_keystore. user_data, key_info->userid, key_info-> handle); printk("key in system keystore\n"); /* Key is in system keystore */ ret = keystore_slot_read(&system_keystore, key_info->userid, key_info->handle, key_info->key_length, key); } else { printk("key goes in user keystore.\n"); /* Key goes in user keystore */ ret = keystore_slot_read(key_info->keystore, key_info->userid, key_info->handle, key_info->key_length, key); } } out: return ret; } /* end fn fsl_shw_read_key */
// // Done // // Shutdown this runcode // void Done() { // Clear the game run code Game::RC::Clear(); // Shutdown game system Game::Done(); // Save user after game is shutdown (for mission progress) User::Save(); LOG_DIAG(("Frame rate: %.1ffps (%.1fdps)", Game::RC::AvgFrameRate(), Game::RC::AvgDisplayRate())); // Shutdown base systems Base::Done(); }
// // User accepted migration request // void Server::Migration::RequestAccepted(const Win32::Socket::Address &address, U32 key) { // A user has accepted migration, tell all of the users to migrate ServerMessage::Data::SessionMigrate *sessionMigrate; Packet &pkt = Packet::Create(ServerMessage::SessionMigrate, sessionMigrate); sessionMigrate->address = address; sessionMigrate->key = key; LOG_DIAG(("Appending session migrate data to the sync data stream")) // We need to tell everyone that the session is migrating though the sync data stream session.items.Append(new Item(0, pkt)); // The session is now considered migrated, we can delete the migration offer = NULL; }
// // LogSource // // For debugging, logs source info // void FileSrcStream::LogSource(U32 indent) { ASSERT(IsSetup()); // Generate the indent String iStr; iStr.Fill(indent, ' '); if (HaveTarget()) { target->LogAllSources(indent); } else { LOG_DIAG(("%sDEAD STREAM", *iStr)); } }
/*! * Wrap a key and retrieve the wrapped value. * * A wrapped key is a key that has been cryptographically obscured. It is * only able to be used with #fsl_shw_establish_key(). * * This function will also release a software key (see #fsl_shw_release_key()) * so it must be re-established before reuse. This is not true of PGM keys. * * This feature is not available for all platforms, nor for all algorithms and * modes. * * @param user_ctx A user context from #fsl_shw_register_user(). * @param key_info The information about the key to be deleted. * @param[out] covered_key The location to store the 48-octet wrapped key. * (This size is based upon the maximum key size * of 32 octets). * * @return A return code of type #fsl_shw_return_t. */ fsl_shw_return_t fsl_shw_extract_key(fsl_shw_uco_t * user_ctx, fsl_shw_sko_t * key_info, uint8_t * covered_key) { fsl_shw_return_t ret = FSL_RETURN_ERROR_S; /* For now, only blocking mode calls are supported */ if (!(user_ctx->flags & FSL_UCO_BLOCKING_MODE)) { ret = FSL_RETURN_BAD_FLAG_S; goto out; } #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Wrapping a key\n"); #endif if (!(key_info->flags & FSL_SKO_KEY_ESTABLISHED)) { #ifdef DIAG_SECURITY_FUNC LOG_DIAG_ARGS("%s: Key not established\n", __FUNCTION__); #endif ret = FSL_RETURN_BAD_FLAG_S; goto out; } /* Verify that a SW key info really belongs to a SW key */ if (key_info->flags & FSL_SKO_KEY_SW_KEY) { /* ret = FSL_RETURN_BAD_FLAG_S; goto out;*/ } ret = wrap(user_ctx, key_info, covered_key); if (ret != FSL_RETURN_OK_S) { goto out; } if (key_info->flags & FSL_SKO_KEY_SW_KEY) { /* Need to deallocate on successful extraction */ (void)dealloc_slot(user_ctx, key_info); /* Mark key not available in the flags */ key_info->flags &= ~(FSL_SKO_KEY_ESTABLISHED | FSL_SKO_KEY_PRESENT); memset(key_info->key, 0, sizeof(key_info->key)); } out: return ret; } /* end fn fsl_shw_extract_key */
/*! * Validate user's wrap key selection * * @param wrap_key The user's desired wrapping key */ static fsl_shw_return_t check_wrap_key(fsl_shw_pf_key_t wrap_key) { /* unable to use desired key */ fsl_shw_return_t ret = FSL_RETURN_NO_RESOURCE_S; if ((wrap_key != FSL_SHW_PF_KEY_IIM) && (wrap_key != FSL_SHW_PF_KEY_RND) && (wrap_key != FSL_SHW_PF_KEY_IIM_RND)) { #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Invalid wrap_key in key wrap/unwrap attempt"); #endif goto out; } ret = FSL_RETURN_OK_S; out: return ret; } /* end fn check_wrap_key */
// // Message // // Display a console message // void CDECL Message(const char *format, ...) { // Process the variable args va_list args; char fmtBuf[MAX_TEXTBUF]; va_start(args, format); vsprintf(fmtBuf, format, args); va_end(args); // Use logging to display message if (logOutput) { LOG_DIAG((fmtBuf)); } // Write to console AddString(fmtBuf, currentType); }
// // VarSys::VarItem::VarItem // // Constructor // VarSys::VarItem::VarItem(const char *identIn, U32 pathCrcIn, VarScope *parent) { ASSERT(parent); // Setup default values type = VI_NONE; itemId = identIn; pathCrc = pathCrcIn; pScope = parent; flags = DEFAULT; pNotify = NULL; // Add to search tree if (allItems.Add(pathCrc, this)) { LOG_DIAG(("Duplicate PathCrc %s [0x%.8X]", identIn, pathCrcIn)); } // Register object creation TrackSys::RegisterConstruction(dTrack); }
fsl_shw_return_t keystore_slot_alloc(fsl_shw_kso_t *keystore, uint32_t size, uint64_t owner_id, uint32_t *slot) { LOCK_INCLUDES; fsl_shw_return_t retval = FSL_RETURN_ERROR_S; #ifdef DIAG_DRV_IF LOG_DIAG("In keystore_slot_alloc."); #endif ACQUIRE_LOCK; if ((keystore->slot_alloc == NULL) || (keystore->user_data == NULL)) { goto out; } #ifdef DIAG_DRV_IF LOG_DIAG_ARGS("key length: %i, handle: %i\n", size, *slot); #endif retval = keystore->slot_alloc(keystore->user_data, size, owner_id, slot); out:RELEASE_LOCK; return retval; }
// // Process the next sync data // Bool ProcessSyncData(U32 &seq, U32 &interval, U32 &time) { StyxNet::EventMessage::Data::SessionSyncData *sessionSyncData = syncData.GetHead(); if (sessionSyncData) { seq = sessionSyncData->seq; interval = sessionSyncData->interval; time = sessionSyncData->time; ASSERT(lag >= interval) lag -= interval; //LOG_DIAG(("SyncData: %08X", sessionSyncData)) //LOG_DIAG(("Data Seq: %d Interval: %d Lag: %d", seq, interval, lag)) SYNC("Data Seq: " << seq) U32 remaining = sessionSyncData->length; const U8 *ptr = sessionSyncData->data; CRC type; CRC from; CRC key; CRC index; U32 length; const U8 *d; //LOG_DIAG(("PreExtract: %d %08X", remaining, ptr)) // Process all of the data while (StyxNet::Client::ExtractSyncData(ptr, remaining, type, from, key, index, length, d)) { //LOG_DIAG(("SyncData: %d %08X %08X %08X %08X %08X %d", remaining, ptr, type, from, key, index, length)) switch (type) { case StyxNet::EventMessage::SyncData: ProcessData(from, key, length, d); // LOG_DIAG(("Processed Sync Data")) break; case StyxNet::EventMessage::SyncStore: data.Store(key, index, length, d); // LOG_DIAG(("Stored data")) ProcessData(from, key, length, d); // LOG_DIAG(("Processed Sync Store Data")) break; case StyxNet::EventMessage::SyncClear: data.Clear(key, index); // LOG_DIAG(("Cleared Data")) break; case StyxNet::EventMessage::SyncFlush: data.Flush(); // LOG_DIAG(("Flush Data")) break; case StyxNet::EventMessage::SyncMigrate: LOG_DIAG(("Sync Migrate")) if (Network::client) { LOG_DIAG(("Migrating")) Network::client->MigrateSession(d, length); Network::StartMigration(); Console::ProcessCmd("sys.game.migrate.start"); } break; } } // LOG_DIAG(("PostExtract")) syncData.Dispose(sessionSyncData); // LOG_DIAG(("Disposed of sessionSyncData")) return (TRUE); } else {
/*! * Place a key into a protected location for use only by cryptographic * algorithms. * * This only needs to be used to a) unwrap a key, or b) set up a key which * could be wrapped with a later call to #fsl_shw_extract_key(). Normal * cleartext keys can simply be placed into #fsl_shw_sko_t key objects with * #fsl_shw_sko_set_key() and used directly. * * The maximum key size supported for wrapped/unwrapped keys is 32 octets. * (This is the maximum reasonable key length on Sahara - 32 octets for an HMAC * key based on SHA-256.) The key size is determined by the @a key_info. The * expected length of @a key can be determined by * #fsl_shw_sko_calculate_wrapped_size() * * The protected key will not be available for use until this operation * successfully completes. * * This feature is not available for all platforms, nor for all algorithms and * modes. * * @param user_ctx A user context from #fsl_shw_register_user(). * @param[in,out] key_info The information about the key to be which will * be established. In the create case, the key * length must be set. * @param establish_type How @a key will be interpreted to establish a * key for use. * @param key If @a establish_type is #FSL_KEY_WRAP_UNWRAP, * this is the location of a wrapped key. If * @a establish_type is #FSL_KEY_WRAP_CREATE, this * parameter can be @a NULL. If @a establish_type * is #FSL_KEY_WRAP_ACCEPT, this is the location * of a plaintext key. * * @return A return code of type #fsl_shw_return_t. */ fsl_shw_return_t fsl_shw_establish_key(fsl_shw_uco_t * user_ctx, fsl_shw_sko_t * key_info, fsl_shw_key_wrap_t establish_type, const uint8_t * key) { fsl_shw_return_t ret; sah_Head_Desc *desc_chain = NULL; uint32_t header = SAH_HDR_RNG_GENERATE; /* Desc. #18 for rand */ unsigned original_key_length = key_info->key_length; unsigned rounded_key_length; /* Write operations into SCC memory require word-multiple number of * bytes. For ACCEPT and CREATE functions, the key length may need * to be rounded up. Calculate. */ if ((original_key_length & 3) != 0) { rounded_key_length = original_key_length + 4 - (original_key_length & 3); } else { rounded_key_length = original_key_length; } /* perform sanity check on the uco */ ret = sah_validate_uco(user_ctx); if (ret != FSL_RETURN_OK_S) { return ret; } ret = do_scc_slot_alloc(user_ctx, key_info->key_length, key_info->userid, &key_info->handle); if (ret == FSL_RETURN_OK_S) { key_info->flags |= FSL_SKO_KEY_ESTABLISHED; switch (establish_type) { case FSL_KEY_WRAP_CREATE: /* Use safe version of key length */ key_info->key_length = rounded_key_length; /* Generate descriptor to put random value into */ ret = add_key_out_desc(header, key_info, NULL, 0, user_ctx->mem_util, &desc_chain); /* Restore actual, desired key length */ key_info->key_length = original_key_length; if (ret == FSL_RETURN_OK_S) { uint32_t old_flags = user_ctx->flags; /* Now put random value into key */ ret = sah_Descriptor_Chain_Execute(desc_chain, user_ctx); /* Restore user's old flag value */ user_ctx->flags = old_flags; } #ifdef DIAG_SECURITY_FUNC else { LOG_DIAG ("Creation of sah_Key_Link failed due to bad" " key flag!\n"); } #endif /*DIAG_SECURITY_FUNC */ break; case FSL_KEY_WRAP_ACCEPT: if (key == NULL) { #ifdef DIAG_SECURITY_FUNC LOG_DIAG("ACCEPT: Red Key is NULL"); #endif ret = FSL_RETURN_ERROR_S; } else { /* Copy in safe number of bytes of Red key */ ret = do_scc_slot_load_slot(user_ctx, key_info->userid, key_info->handle, key, rounded_key_length); } break; case FSL_KEY_WRAP_UNWRAP: /* For now, disallow non-blocking calls. */ if (!(user_ctx->flags & FSL_UCO_BLOCKING_MODE)) { ret = FSL_RETURN_BAD_FLAG_S; } else if (key == NULL) { ret = FSL_RETURN_ERROR_S; } else { ret = unwrap(user_ctx, key_info, key); if (ret != FSL_RETURN_OK_S) { } } break; default: ret = FSL_RETURN_BAD_FLAG_S; break; } /* switch */ if (ret != FSL_RETURN_OK_S) { fsl_shw_return_t scc_err; scc_err = do_scc_slot_dealloc(user_ctx, key_info->userid, key_info->handle); key_info->flags &= ~FSL_SKO_KEY_ESTABLISHED; } } return ret; }
/*! * Perform wrapping of a black key from a RED slot * * @param user_ctx A user context from #fsl_shw_register_user(). * @param[in,out] key_info The information about the key to be which will * be wrapped... key length, slot info, etc. * @param black_key Place to store encrypted key * * @return A return code of type #fsl_shw_return_t. */ static fsl_shw_return_t wrap(fsl_shw_uco_t * user_ctx, fsl_shw_sko_t * key_info, uint8_t * black_key) { fsl_shw_return_t ret; sah_Head_Desc *desc_chain = NULL; unsigned slots_allocated = 0; /* boolean */ fsl_shw_sko_t T_key_info; /* for holding T */ fsl_shw_sko_t KEK_key_info; /* for holding KEK */ black_key[LENGTH_OFFSET] = key_info->key_length; black_key[ALGORITHM_OFFSET] = key_info->algorithm; memcpy(&T_key_info, key_info, sizeof(T_key_info)); fsl_shw_sko_set_key_length(&T_key_info, T_LENGTH); T_key_info.algorithm = FSL_KEY_ALG_HMAC; memcpy(&KEK_key_info, &T_key_info, sizeof(KEK_key_info)); KEK_key_info.algorithm = FSL_KEY_ALG_AES; ret = do_scc_slot_alloc(user_ctx, T_LENGTH, key_info->userid, &T_key_info.handle); if (ret == FSL_RETURN_OK_S) { ret = do_scc_slot_alloc(user_ctx, KEK_LENGTH, key_info->userid, &KEK_key_info.handle); if (ret != FSL_RETURN_OK_S) { #ifdef DIAG_SECURITY_FUNC LOG_DIAG("do_scc_slot_alloc() failed"); #endif do_scc_slot_dealloc(user_ctx, key_info->userid, T_key_info.handle); } else { slots_allocated = 1; } } /* Set up to compute everything except T' ... */ if (ret == FSL_RETURN_OK_S) { uint32_t header; #ifndef DO_REPEATABLE_WRAP /* Compute T = RND() */ header = SAH_HDR_RNG_GENERATE; /* Desc. #18 */ ret = add_key_out_desc(header, &T_key_info, NULL, 0, user_ctx->mem_util, &desc_chain); #else ret = do_scc_slot_load_slot(user_ctx, T_key_info.userid, T_key_info.handle, T_block, T_key_info.key_length); #endif /* Compute KEK = SHA1(T | Ownerid) */ if (ret == FSL_RETURN_OK_S) { sah_Link *link1; sah_Link *link2; header = (SAH_HDR_MDHA_SET_MODE_HASH /* #8 */ ^ insert_mdha_init ^ insert_mdha_algorithm[FSL_HASH_ALG_SHA1] ^ insert_mdha_pdata); /* Input - Start with T */ ret = sah_Create_Key_Link(user_ctx->mem_util, &link1, &T_key_info); if (ret == FSL_RETURN_OK_S) { /* Still input - append ownerid */ ret = sah_Append_Link(user_ctx->mem_util, link1, (void *)&key_info->userid, sizeof(key_info->userid), SAH_USES_LINK_DATA); } if (ret == FSL_RETURN_OK_S) { /* Output - KEK goes into RED slot */ ret = sah_Create_Key_Link(user_ctx->mem_util, &link2, &KEK_key_info); } /* Put the Hash calculation into the chain. */ if (ret == FSL_RETURN_OK_S) { ret = sah_Append_Desc(user_ctx->mem_util, &desc_chain, header, link1, link2); } } /* Compute KEY' = AES-encrypt(KEK, KEY) */ if (ret == FSL_RETURN_OK_S) { header = (SAH_HDR_SKHA_SET_MODE_IV_KEY /* #1 */ ^ insert_skha_mode[FSL_SYM_MODE_CTR] ^ insert_skha_algorithm[FSL_KEY_ALG_AES] ^ insert_skha_modulus[FSL_CTR_MOD_128]); /* Set up KEK as key to use */ ret = add_in_key_desc(header, NULL, 0, &KEK_key_info, user_ctx->mem_util, &desc_chain); /* Set up KEY as input, KEY' as output */ if (ret == FSL_RETURN_OK_S) { header = SAH_HDR_SKHA_ENC_DEC; /* #4 */ ret = add_key_out_desc(header, key_info, black_key + KEY_PRIME_OFFSET, key_info->key_length, user_ctx->mem_util, &desc_chain); } #ifdef DIAG_SECURITY_FUNC if (ret != FSL_RETURN_OK_S) { LOG_DIAG ("Creation of sah_Key_Link failed due to bad key" " flag!\n"); } #endif /*DIAG_SECURITY_FUNC */ } /* Compute and store ICV into Black Key */ if (ret == FSL_RETURN_OK_S) { ret = create_icv_calc(user_ctx, &desc_chain, &T_key_info, black_key, key_info->key_length, black_key + ICV_OFFSET); #ifdef DIAG_SECURITY_FUNC if (ret != FSL_RETURN_OK_S) { LOG_DIAG ("Creation of sah_Key_Link failed due to bad key" " flag!\n"); } #endif /*DIAG_SECURITY_FUNC */ } } /* Now get Sahara to do the work. */ if (ret == FSL_RETURN_OK_S) { ret = sah_Descriptor_Chain_Execute(desc_chain, user_ctx); #ifdef DIAG_SECURITY_FUNC if (ret != FSL_RETURN_OK_S) { LOG_DIAG("sah_Descriptor_Chain_Execute() failed"); } #endif } /* Compute T' = SLID_encrypt(T); Result goes to Black Key */ if (ret == FSL_RETURN_OK_S) { ret = do_scc_slot_encrypt(user_ctx, T_key_info.userid, T_key_info.handle, T_LENGTH, black_key + T_PRIME_OFFSET); #ifdef DIAG_SECURITY_FUNC if (ret != FSL_RETURN_OK_S) { LOG_DIAG("do_scc_slot_encrypt() failed"); } #endif } if (slots_allocated) { do_scc_slot_dealloc(user_ctx, key_info->userid, T_key_info.handle); do_scc_slot_dealloc(user_ctx, key_info->userid, KEK_key_info.handle); } return ret; } /* wrap */
/*! * Perform unwrapping of a black key into a RED slot * * @param user_ctx A user context from #fsl_shw_register_user(). * @param[in,out] key_info The information about the key to be which will * be unwrapped... key length, slot info, etc. * @param black_key Encrypted key * * @return A return code of type #fsl_shw_return_t. */ static fsl_shw_return_t unwrap(fsl_shw_uco_t * user_ctx, fsl_shw_sko_t * key_info, const uint8_t * black_key) { fsl_shw_return_t ret = FSL_RETURN_ERROR_S; sah_Mem_Util *mu = user_ctx->mem_util; uint8_t *hmac = mu->mu_malloc(mu->mu_ref, ICV_LENGTH); if (hmac == NULL) { ret = FSL_RETURN_NO_RESOURCE_S; } else { sah_Head_Desc *desc_chain = NULL; fsl_shw_sko_t t_key_info; unsigned i; /* Set up key_info for "T" - use same slot as eventual key */ fsl_shw_sko_init(&t_key_info, FSL_KEY_ALG_AES); t_key_info.userid = key_info->userid; t_key_info.handle = key_info->handle; t_key_info.flags = key_info->flags; t_key_info.key_length = T_LENGTH; /* Compute T = SLID_decrypt(T'); leave in RED slot */ ret = do_scc_slot_decrypt(user_ctx, key_info->userid, t_key_info.handle, T_LENGTH, black_key + T_PRIME_OFFSET); /* Compute ICV = HMAC(T, ownerid | len | alg | key' */ if (ret == FSL_RETURN_OK_S) { ret = create_icv_calc(user_ctx, &desc_chain, &t_key_info, black_key, key_info->key_length, hmac); if (ret == FSL_RETURN_OK_S) { ret = sah_Descriptor_Chain_Execute(desc_chain, user_ctx); desc_chain = NULL; } #ifdef DIAG_SECURITY_FUNC else { LOG_DIAG ("Creation of sah_Key_Link failed due to bad key" " flag!\n"); } #endif /*DIAG_SECURITY_FUNC */ /* Check computed ICV against value in Black Key */ if (ret == FSL_RETURN_OK_S) { for (i = 0; i < ICV_LENGTH; i++) { if (black_key[ICV_OFFSET + i] != hmac[i]) { ret = FSL_RETURN_AUTH_FAILED_S; break; } } } /* This is no longer needed. */ mu->mu_free(mu->mu_ref, hmac); /* Compute KEK = SHA1(T | ownerid). Rewrite slot with value */ if (ret == FSL_RETURN_OK_S) { sah_Link *link1 = NULL; sah_Link *link2 = NULL; uint32_t header; header = (SAH_HDR_MDHA_SET_MODE_HASH /* #8 */ ^ insert_mdha_init ^ insert_mdha_algorithm_sha1 ^ insert_mdha_pdata); /* Input - Start with T */ ret = sah_Create_Key_Link(user_ctx->mem_util, &link1, &t_key_info); if (ret == FSL_RETURN_OK_S) { /* Still input - append ownerid */ ret = sah_Append_Link(user_ctx->mem_util, link1, (void *)&key_info-> userid, sizeof(key_info-> userid), SAH_USES_LINK_DATA); } if (ret == FSL_RETURN_OK_S) { /* Output - KEK goes into RED slot */ ret = sah_Create_Key_Link(user_ctx-> mem_util, &link2, &t_key_info); } if (ret == FSL_RETURN_OK_S) { /* Put the Hash calculation into the chain. */ ret = sah_Append_Desc(user_ctx->mem_util, &desc_chain, header, link1, link2); } } /* Compute KEY = AES-decrypt(KEK, KEY') */ if (ret == FSL_RETURN_OK_S) { uint32_t header; unsigned rounded_key_length; unsigned original_key_length = key_info->key_length; header = (SAH_HDR_SKHA_SET_MODE_IV_KEY /* #1 */ ^ insert_skha_mode_ctr ^ insert_skha_algorithm_aes ^ insert_skha_modulus_128); /* Load KEK in as the key to use */ ret = add_in_key_desc(header, NULL, 0, &t_key_info, user_ctx->mem_util, &desc_chain); /* Make sure that KEY = AES(KEK, KEY') step writes a multiple of words into the SCC to avoid 'Byte Access errors.' */ if ((original_key_length & 3) != 0) { rounded_key_length = original_key_length + 4 - (original_key_length & 3); } else { rounded_key_length = original_key_length; } key_info->key_length = rounded_key_length; if (ret == FSL_RETURN_OK_S) { /* Now set up for computation. Result in RED */ header = SAH_HDR_SKHA_ENC_DEC; /* #4 */ ret = add_in_key_desc(header, black_key + KEY_PRIME_OFFSET, rounded_key_length, key_info, user_ctx->mem_util, &desc_chain); key_info->key_length = original_key_length; /* Perform the operation */ if (ret == FSL_RETURN_OK_S) { ret = sah_Descriptor_Chain_Execute (desc_chain, user_ctx); } } } /* Erase tracks */ t_key_info.userid = 0xdeadbeef; t_key_info.handle = 0xdeadbeef; } } return ret; } /* unwrap */
/*! * Create Key Link * * @brief Allocate Memory for Link structure and populate using key info * object * * @param mu Memory functions * @param link Pointer to store address of link to be created * @param key_info Pointer to Key Info object to be referenced * * @return A return code of type #fsl_shw_return_t. */ fsl_shw_return_t sah_Create_Key_Link(const sah_Mem_Util * mu, sah_Link ** link, fsl_shw_sko_t * key_info) { #ifdef DIAG_SECURITY_FUNC char diag[50]; #endif /*DIAG_SECURITY_FUNC */ fsl_shw_return_t status = FSL_RETURN_NO_RESOURCE_S; sah_Link_Flags flags = 0; *link = mu->mu_alloc_link(mu->mu_ref); /* populate link if memory allocation successful */ if (*link != NULL) { (*link)->len = key_info->key_length; if (key_info->flags & FSL_SKO_KEY_PRESENT) { (*link)->data = key_info->key; status = FSL_RETURN_OK_S; } else { if (key_info->flags & FSL_SKO_KEY_ESTABLISHED) { (*link)->slot = key_info->handle; (*link)->ownerid = key_info->userid; (*link)->data = 0; flags |= SAH_STORED_KEY_INFO; status = FSL_RETURN_OK_S; } else { /* the flag is bad. Should never get here */ status = FSL_RETURN_BAD_FLAG_S; } } (*link)->next = NULL; (*link)->flags = flags; #ifdef DIAG_SECURITY_FUNC if (status == FSL_RETURN_OK_S) { LOG_DIAG("Created Link"); LOG_DIAG("------------"); sprintf(diag, " address = 0x%x", (int)*link); LOG_DIAG(diag); sprintf(diag, " link->len = %d", (*link)->len); LOG_DIAG(diag); if (key_info->flags & FSL_SKO_KEY_ESTABLISHED) { sprintf(diag, " link->slot = 0x%x", (*link)->slot); LOG_DIAG(diag); } else { sprintf(diag, " link->data = 0x%x", (int)(*link)->data); LOG_DIAG(diag); } sprintf(diag, " link->flags = 0x%x", (*link)->flags); LOG_DIAG(diag); LOG_DIAG(" link->next = NULL"); } #endif /*DIAG_SECURITY_FUNC */ if (status == FSL_RETURN_BAD_FLAG_S) { mu->mu_free_link(mu->mu_ref, *link); *link = NULL; #ifdef DIAG_SECURITY_FUNC LOG_DIAG ("Creation of sah_Key_Link failed due to bad key flag!\n"); #endif /*DIAG_SECURITY_FUNC */ } } else { #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Allocation of memory for sah_Key_Link failed!\n"); #endif /*DIAG_SECURITY_FUNC */ } return status; }
/*! * Create and populate a single descriptor * * The pointer and length fields will be be set based on the chains passed in * as @a link1 and @a link2. * * @param mu Memory utility suite * @param desc Location to store pointer of new descriptor * @param head_desc Non-zero if this will be first in chain; zero otherwise * @param header The Sahara header value to store in the descriptor * @param link1 A value (or NULL) for the first ptr * @param link2 A value (or NULL) for the second ptr * * @post If allocation succeeded, the @a link1 and @link2 will be linked into * the descriptor. If allocation failed, those link structues will be * freed, and the @a desc will be unchanged. * * @return A return code of type #fsl_shw_return_t. */ static fsl_shw_return_t sah_Create_Desc(const sah_Mem_Util * mu, sah_Desc ** desc, int head_desc, uint32_t header, sah_Link * link1, sah_Link * link2) { fsl_shw_return_t status = FSL_RETURN_NO_RESOURCE_S; #ifdef DIAG_SECURITY_FUNC char diag[50]; #endif /*DIAG_SECURITY_FUNC */ if (head_desc != 0) { *desc = (sah_Desc *) mu->mu_alloc_head_desc(mu->mu_ref); } else { *desc = mu->mu_alloc_desc(mu->mu_ref); } /* populate descriptor if memory allocation successful */ if ((*desc) != NULL) { sah_Link *temp_link; status = FSL_RETURN_OK_S; (*desc)->header = header; temp_link = (*desc)->ptr1 = link1; (*desc)->len1 = 0; while (temp_link != NULL) { (*desc)->len1 += temp_link->len; temp_link = temp_link->next; } temp_link = (*desc)->ptr2 = link2; (*desc)->len2 = 0; while (temp_link != NULL) { (*desc)->len2 += temp_link->len; temp_link = temp_link->next; } (*desc)->next = NULL; #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Created Desc"); LOG_DIAG("------------"); sprintf(diag, " address = 0x%x", (int)*desc); LOG_DIAG(diag); sprintf(diag, " desc->header = 0x%x", (*desc)->header); LOG_DIAG(diag); sprintf(diag, " desc->len1 = %d", (*desc)->len1); LOG_DIAG(diag); sprintf(diag, " desc->ptr1 = 0x%x", (int)((*desc)->ptr1)); LOG_DIAG(diag); sprintf(diag, " desc->len2 = %d", (*desc)->len2); LOG_DIAG(diag); sprintf(diag, " desc->ptr2 = 0x%x", (int)((*desc)->ptr2)); LOG_DIAG(diag); sprintf(diag, " desc->next = 0x%x", (int)((*desc)->next)); LOG_DIAG(diag); #endif /*DIAG_SECURITY_FUNC */ } else { #ifdef DIAG_SECURITY_FUNC LOG_DIAG("Allocation of memory for sah_Desc failed!\n"); #endif /*DIAG_SECURITY_FUNC */ /* Destroy the links, otherwise the memory allocated by the Security Function layer for the links (and possibly the data within the links) will be lost */ if (link1 != NULL) { sah_Destroy_Link(mu, link1); } if (link2 != NULL) { sah_Destroy_Link(mu, link2); } } return status; }
// // RunCodes::Process // void RunCodes::Process() { char buf[256]; // Run the optional run once function if (runOnceProc) { runOnceProc(); runOnceProc = NULL; } // Run code change was requested if (changeRC) { // Ensure we are changing to a valid run code if (nextRC == NULL) { ERR_FATAL(("[%s] Run code is NULL", ident.str)); } // Check with current runcode if we are allowed to leave it // However, we are always allowed to quit if (currentRC && currentRC->fnNotify && (nextRC->ident.crc != 0xB4729720)) // "Quit" { if (!currentRC->fnNotify(0x2F312211)) // "CanLeave" { changeRC = FALSE; } } } if (changeRC) { // Shutdown the current run code if (currentRC && currentRC->fnDone) { currentRC->fnDone(); } // Changed over ok currentRC = nextRC; nextRC = NULL; changeRC = FALSE; // Initialize the new run code LOG_DIAG(("[%s] Entering run code [%s]", ident.str, currentRC->ident.str)); if (currentRC->fnInit) { currentRC->fnInit(); } // Execute post-init cfg file (does not need to exist) Utils::Sprintf(buf, 256, "runcode_%s_%s.cfg", ident.str, currentRC->ident.str); Main::Exec(buf, Main::ScopeHandler, FALSE); // And optional user post-init cfg file Utils::Sprintf(buf, 256, "user_%s_%s.cfg", ident.str, currentRC->ident.str); Main::Exec(buf, Main::ScopeHandler, FALSE); // If there's a post load function then go with it if (currentRC->fnPost) { currentRC->fnPost(); } } else { // Execute current runcode processing function ASSERT(currentRC); if (!currentRC->fnGame) { ERR_FATAL(("[%s] No process function for [%s] to be processed!", ident.str, currentRC->ident.str)) } currentRC->fnGame(); } }
// // Place // // Place units for the given team // void Place(Team *team) { ASSERT(initialized) ASSERT(team) // Get the side for this team Sides::Side &side = Sides::GetSide(team->GetSide()); // Get the start region for this team if (RegionObj *region = team->GetStartRegion()) { // Get the midpoint from the region Point<F32> startPoint(region->GetMidPoint()); // Ensure point is in the playfield WorldCtrl::ClampPlayFieldPoint(startPoint); // Adjust so point is always in the centre of a cell Point<U32> startPointCells; WorldCtrl::MetresToCellPoint(startPoint, startPointCells); WorldCtrl::CellToMetrePoint(startPointCells, startPoint); // Get the vector from the start point to the centre of the map Vector centre ( Vector(WorldCtrl::MetreMapX() * 0.5F, 0.0F, WorldCtrl::MetreMapZ() * 0.5F) - Vector(startPoint.x, 0.0F, startPoint.z) ); // Normalize it centre.Normalize(); // Work out the initial direction VectorDir dir; centre.Convert(dir); WorldCtrl::CompassDir compassDir = WorldCtrl::GetCompassDirection(centre); F32 startDirection = -WorldCtrl::GetCompassAngle(compassDir); // Place each item for (NList<Item>::Iterator i(&items); *i; i++) { // Get the item Item &item = **i; // Get the type mapping for this item if (const char *typeName = side.GetMapping(item.type.crc)) { // Try and find the specified type if (UnitObjType *type = GameObjCtrl::FindType<UnitObjType>(typeName)) { // Calculate the direction from the start point F32 direction = startDirection + item.direction; VectorDir::FixU(direction); // Calculate the orientation of the unit F32 orientation = startDirection + item.orientation; VectorDir::FixU(orientation); // Calculate final position Vector pos; pos.x = F32(cos(direction)); pos.y = 0.0f; pos.z = F32(sin(direction)); pos *= item.distance; pos.x += startPoint.x; pos.z += startPoint.z; pos.y += TerrainData::FindFloorWithWater(pos.x, pos.z); // Ensure the resources are initialized for this type type->InitializeResources(); // Create the unit if (!type->SpawnClosest(pos, team, FALSE, orientation)) { LOG_DIAG(("Unable to spawn [%s] for team [%s]", typeName, team->GetName())); } } } } } }