static NTSTATUS IopDeviceStatus(PPLUGPLAY_CONTROL_STATUS_DATA StatusData) { PDEVICE_OBJECT DeviceObject; PDEVICE_NODE DeviceNode; ULONG Operation = 0; ULONG DeviceStatus = 0; ULONG DeviceProblem = 0; UNICODE_STRING DeviceInstance; NTSTATUS Status; DPRINT("IopDeviceStatus() called\n"); Status = IopCaptureUnicodeString(&DeviceInstance, &StatusData->DeviceInstance); if (!NT_SUCCESS(Status)) { return Status; } DPRINT("Device name: '%wZ'\n", &DeviceInstance); _SEH2_TRY { Operation = StatusData->Operation; if (Operation == PNP_SET_DEVICE_STATUS) { DeviceStatus = StatusData->DeviceStatus; DeviceProblem = StatusData->DeviceProblem; } } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { if (DeviceInstance.Buffer != NULL) { ExFreePool(DeviceInstance.Buffer); } _SEH2_YIELD(return _SEH2_GetExceptionCode()); } _SEH2_END; /* Get the device object */ DeviceObject = IopGetDeviceObjectFromDeviceInstance(&DeviceInstance); if (DeviceInstance.Buffer != NULL) { ExFreePool(DeviceInstance.Buffer); } if (DeviceObject == NULL) { return STATUS_NO_SUCH_DEVICE; } DeviceNode = IopGetDeviceNode(DeviceObject); switch (Operation) { case PNP_GET_DEVICE_STATUS: DPRINT("Get status data\n"); DeviceStatus = IopGetDeviceNodeStatus(DeviceNode); DeviceProblem = DeviceNode->Problem; break; case PNP_SET_DEVICE_STATUS: DPRINT1("Set status data is NOT SUPPORTED\n"); break; case PNP_CLEAR_DEVICE_STATUS: DPRINT1("FIXME: Clear status data!\n"); break; } ObDereferenceObject(DeviceObject); if (Operation == PNP_GET_DEVICE_STATUS) { _SEH2_TRY { StatusData->DeviceStatus = DeviceStatus; StatusData->DeviceProblem = DeviceProblem; } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { Status = _SEH2_GetExceptionCode(); } _SEH2_END; }
static NTSTATUS InitDevice( IN PUNICODE_STRING RegistryPath, IN PVOID Context) { // PDEVICE_INSTANCE Instance = Context; PDEVICE_OBJECT DeviceObject; // = Context; PDEVICE_EXTENSION Parameters; // = DeviceObject->DeviceExtension; UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\MidiOut0"); UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\??\\MidiOut0"); // CONFIG Config; RTL_QUERY_REGISTRY_TABLE Table[2]; NTSTATUS s; // This is TEMPORARY, to ensure that we don't process more than 1 device. // I'll remove this limitation in the future. if (DeviceCount > 0) { DPRINT("Sorry - only 1 device supported by MPU401 driver at present :(\n"); return STATUS_NOT_IMPLEMENTED; } DPRINT("Creating IO device\n"); s = IoCreateDevice(Context, // driverobject sizeof(DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_SOUND, // Correct? 0, FALSE, &DeviceObject); if (!NT_SUCCESS(s)) return s; DPRINT("Device Extension at 0x%x\n", DeviceObject->DeviceExtension); Parameters = DeviceObject->DeviceExtension; DPRINT("Creating DOS link\n"); /* Create the dos device link */ IoCreateSymbolicLink(&SymlinkName, &DeviceName); DPRINT("Initializing device\n"); // DPRINT("Allocating memory for parameters structure\n"); // Bodged: // Parameters = (PDEVICE_EXTENSION)ExAllocatePool(NonPagedPool, sizeof(DEVICE_EXTENSION)); // DeviceObject->DeviceExtension = Parameters; // Parameters = Instance->DriverObject->DriverExtension; DPRINT("DeviceObject at 0x%x, DeviceExtension at 0x%x\n", DeviceObject, Parameters); if (! Parameters) { DPRINT("NULL POINTER!\n"); return STATUS_INSUFFICIENT_RESOURCES; } // Instance->DriverObject->DriverExtension = Parameters; DPRINT("Setting reg path\n"); Parameters->RegistryPath = RegistryPath; // Parameters->DriverObject = Instance->DriverObject; DPRINT("Zeroing table memory and setting query routine\n"); RtlZeroMemory(Table, sizeof(Table)); Table[0].QueryRoutine = LoadSettings; DPRINT("Setting port and IRQ defaults\n"); Parameters->Port = DEFAULT_PORT; Parameters->IRQ = DEFAULT_IRQ; // Only to be enabled once we can get support for multiple cards working :) /* DPRINT("Loading settings from: %S\n", RegistryPath); s = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE, RegistryPath, Table, &Parameters, NULL); */ if (! NT_SUCCESS(s)) return s; DPRINT("Port 0x%x IRQ %d\n", Parameters->Port, Parameters->IRQ); // Instance->P // Enter UART mode (should be done in init phase if (! InitUARTMode(Parameters->Port)) { DPRINT("UART mode initialization FAILED!\n"); // Set state indication somehow // Failure - what error code do we give?! // return STATUS_???? } DeviceCount ++; return STATUS_SUCCESS; }
/// <summary> /// Get kernel build number /// </summary> /// <param name="pBuildNO">Build number.</param> /// <returns>Status code</returns> NTSTATUS BBGetBuildNO( OUT PULONG pBuildNo ) { ASSERT( pBuildNo != NULL ); if (pBuildNo == 0) return STATUS_INVALID_PARAMETER; NTSTATUS status = STATUS_SUCCESS; UNICODE_STRING strRegKey = { 0 }; UNICODE_STRING strRegValue = { 0 }; UNICODE_STRING strVerVal = { 0 }; HANDLE hKey = NULL; OBJECT_ATTRIBUTES keyAttr = { 0 }; RtlUnicodeStringInit( &strRegKey, L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion" ); RtlUnicodeStringInit( &strRegValue, L"BuildLabEx" ); InitializeObjectAttributes( &keyAttr, &strRegKey, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL ); status = ZwOpenKey( &hKey, KEY_READ, &keyAttr ); if (NT_SUCCESS( status )) { PKEY_VALUE_FULL_INFORMATION pValueInfo = ExAllocatePoolWithTag( PagedPool, 0x1000, BB_POOL_TAG ); ULONG bytes = 0; if (pValueInfo) { status = ZwQueryValueKey( hKey, &strRegValue, KeyValueFullInformation, pValueInfo, 0x1000, &bytes ); if (NT_SUCCESS( status )) { PWCHAR pData = (PWCHAR)((PUCHAR)pValueInfo->Name + pValueInfo->NameLength); for (ULONG i = 0; i < pValueInfo->DataLength; i++) { if (pData[i] == L'.') { for (ULONG j = i + 1; j < pValueInfo->DataLength; j++) { if (pData[j] == L'.') { strVerVal.Buffer = &pData[i] + 1; strVerVal.Length = strVerVal.MaximumLength = (USHORT)((j - i) * sizeof( WCHAR )); status = RtlUnicodeStringToInteger( &strVerVal, 10, pBuildNo ); goto skip1; } } } } skip1:; } ExFreePoolWithTag( pValueInfo, BB_POOL_TAG ); } else status = STATUS_NO_MEMORY; ZwClose( hKey ); } else DPRINT( "BlackBone: %s: ZwOpenKey failed with status 0x%X\n", __FUNCTION__, status ); return status; }
kdb_incr_result_t * iprop_get_updates_1(kdb_last_t *arg, struct svc_req *rqstp) { static kdb_incr_result_t ret; char *whoami = "iprop_get_updates_1"; int kret; kadm5_server_handle_t handle = global_server_handle; char *client_name = NULL, *service_name = NULL; gss_name_t name = NULL; OM_uint32 min_stat; char obuf[256] = {0}; /* default return code */ ret.ret = UPDATE_ERROR; DPRINT(("%s: start, last_sno=%u\n", whoami, (ulong_t)arg->last_sno)); if (!handle) { krb5_klog_syslog(LOG_ERR, gettext("%s: server handle is NULL"), whoami); goto out; } if (setup_gss_names(rqstp, &client_name, &service_name) < 0) { krb5_klog_syslog(LOG_ERR, gettext("%s: setup_gss_names failed"), whoami); goto out; } DPRINT(("%s: clprinc=`%s'\n\tsvcprinc=`%s'\n", whoami, client_name, service_name)); if (!(name = get_clnt_name(rqstp))) { krb5_klog_syslog(LOG_ERR, gettext("%s: Couldn't obtain client's name"), whoami); goto out; } if (!kadm5int_acl_check(handle->context, name, ACL_IPROP, NULL, NULL)) { ret.ret = UPDATE_PERM_DENIED; audit_kadmind_unauth(rqstp->rq_xprt, l_port, whoami, "<null>", client_name); krb5_klog_syslog(LOG_NOTICE, LOG_UNAUTH, whoami, "<null>", client_name, service_name, client_addr(rqstp, abuf)); goto out; } kret = ulog_get_entries(handle->context, *arg, &ret); if (ret.ret == UPDATE_OK) { (void) snprintf(obuf, sizeof (obuf), gettext("%s; Incoming SerialNo=%u; Outgoing SerialNo=%u"), replystr(ret.ret), (ulong_t)arg->last_sno, (ulong_t)ret.lastentry.last_sno); } else { (void) snprintf(obuf, sizeof (obuf), gettext("%s; Incoming SerialNo=%u; Outgoing SerialNo=N/A"), replystr(ret.ret), (ulong_t)arg->last_sno); } audit_kadmind_auth(rqstp->rq_xprt, l_port, whoami, obuf, client_name, kret); krb5_klog_syslog(LOG_NOTICE, LOG_DONE, whoami, obuf, ((kret == 0) ? "success" : error_message(kret)), client_name, service_name, client_addr(rqstp, abuf)); out: if (nofork) debprret(whoami, ret.ret, ret.lastentry.last_sno); if (client_name) free(client_name); if (service_name) free(service_name); if (name) gss_release_name(&min_stat, &name); return (&ret); }
ULONG NTAPI HalpGetPCIData(IN PBUS_HANDLER BusHandler, IN PBUS_HANDLER RootHandler, IN PCI_SLOT_NUMBER Slot, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length) { UCHAR PciBuffer[PCI_COMMON_HDR_LENGTH]; PPCI_COMMON_CONFIG PciConfig = (PPCI_COMMON_CONFIG)PciBuffer; ULONG Len = 0; #ifdef SARCH_XBOX /* Trying to get PCI config data from devices 0:0:1 and 0:0:2 will completely * hang the Xbox. Also, the device number doesn't seem to be decoded for the * video card, so it appears to be present on 1:0:0 - 1:31:0. * We hack around these problems by indicating "device not present" for devices * 0:0:1, 0:0:2, 1:1:0, 1:2:0, 1:3:0, ...., 1:31:0 */ if ((0 == BusHandler->BusNumber && 0 == Slot.u.bits.DeviceNumber && (1 == Slot.u.bits.FunctionNumber || 2 == Slot.u.bits.FunctionNumber)) || (1 == BusHandler->BusNumber && 0 != Slot.u.bits.DeviceNumber)) { DPRINT("Blacklisted PCI slot\n"); if (0 == Offset && sizeof(USHORT) <= Length) { *(PUSHORT)Buffer = PCI_INVALID_VENDORID; return sizeof(USHORT); } return 0; } #endif /* Normalize the length */ if (Length > sizeof(PCI_COMMON_CONFIG)) Length = sizeof(PCI_COMMON_CONFIG); /* Check if this is a vendor-specific read */ if (Offset >= PCI_COMMON_HDR_LENGTH) { /* Read the header */ HalpReadPCIConfig(BusHandler, Slot, PciConfig, 0, sizeof(ULONG)); /* Make sure the vendor is valid */ if (PciConfig->VendorID == PCI_INVALID_VENDORID) return 0; } else { /* Read the entire header */ Len = PCI_COMMON_HDR_LENGTH; HalpReadPCIConfig(BusHandler, Slot, PciConfig, 0, Len); /* Validate the vendor ID */ if (PciConfig->VendorID == PCI_INVALID_VENDORID) { /* It's invalid, but we want to return this much */ Len = sizeof(USHORT); } /* Now check if there's space left */ if (Len < Offset) return 0; /* There is, so return what's after the offset and normalize */ Len -= Offset; if (Len > Length) Len = Length; /* Copy the data into the caller's buffer */ RtlMoveMemory(Buffer, PciBuffer + Offset, Len); /* Update buffer and offset, decrement total length */ Offset += Len; Buffer = (PVOID)((ULONG_PTR)Buffer + Len); Length -= Len; } /* Now we still have something to copy */ if (Length) { /* Check if it's vendor-specific data */ if (Offset >= PCI_COMMON_HDR_LENGTH) { /* Read it now */ HalpReadPCIConfig(BusHandler, Slot, Buffer, Offset, Length); Len += Length; } } /* Update the total length read */ return Len; }
void write_xmms_config() { /*char tempname[100];*/ char *tempname = (char *)malloc(sizeof(char)*100); int count; GSList *position = cdcover_config.cover_searchpaths; GSList *positionext = cdcover_config.cover_extensions; mcs_handle_t *config; DPRINT (__DEBUG_GENERAL__,"Writing config"); config = aud_cfg_db_open (); if (config) { // Window position aud_cfg_db_set_bool (config,PLUGIN_NAME,"savewindowpos",cdcover_config.save_window_pos); aud_cfg_db_set_int (config,PLUGIN_NAME,"windowposx",cdcover_config.winpos_x); aud_cfg_db_set_int (config,PLUGIN_NAME,"windowposy",cdcover_config.winpos_y); // Aspect ratio aud_cfg_db_set_bool (config,PLUGIN_NAME,"aspectratio",cdcover_config.preserve_aspectratio); // Iterate through the search list and save the paths count=0; while (position!=NULL) { count++; sprintf (tempname,"path%d",count); aud_cfg_db_set_string (config,PLUGIN_NAME,tempname,position->data); //printf("Wrote path %s (%d, %s)\n", (char *)position->data, count, tempname); position = g_slist_next (position); } //printf("Done writing paths\n"); // Delete the next key, so there's a hole and read_xmms_config can stop here // Not too nice, as we probably leave garbage in the xmms config file sprintf (tempname,"path%d",count+1); aud_cfg_db_unset_key (config,PLUGIN_NAME,tempname); // Iterate through the search list and save the extensions count=0; //printf("About to write extensions\n"); while (positionext!=NULL) { count++; sprintf (tempname,"ext%d",count); aud_cfg_db_set_string (config,PLUGIN_NAME,tempname,positionext->data); //printf("Wrote extension %s (%d, %s)\n", (char *)positionext->data, count, tempname); positionext = g_slist_next (positionext); } //printf("Done with the extensions too\n"); // Delete the next key, so there's a hole and read_xmms_config can stop here // Not too nice, as we probably leave garbage in the xmms config file sprintf (tempname,"ext%d",count+1); aud_cfg_db_unset_key (config,PLUGIN_NAME,tempname); // Save the skin if (cdcover_config.skin_path!=NULL) { // Save the user selected skin aud_cfg_db_set_string (config,PLUGIN_NAME,"skinpath",cdcover_config.skin_path); } else { // Built in default skin, delete the key aud_cfg_db_unset_key (config,PLUGIN_NAME,"skinpath"); } // Write and then free the config //printf("About to close config file\n"); aud_cfg_db_close (config); //printf("Closed config file\n"); } else { DPRINT (__DEBUG_GENERAL__,"cannot open config file for writing"); } }
dp_result_t pv_update(pv_t *pv, dpid_t owner) { size_t len, hdrlen; pv_peer_t *peer; assoctab_item_t *pe; pv_var_t *pvar; dp_result_t err; playerHdl_t errHdl; time_t interval; int i, j; char buf[dpio_MAXLEN_RELIABLE]; if (!pv) { DPRINT(("pv_update: pv null\n")); return dp_RES_BUG; } /* Wait 'til previous transmission has had time to get sent. */ if ((long)(pv->dp->now - pv->next_send) < 0) return dp_RES_OK; /* Set default next-check-time if no transmission this time. */ pv->next_send = pv->dp->now + pv->dp->clocksPerSec / 8; /* To propagate the given id's variables, need to get access to them */ peer = (pv_peer_t *)assoctab_subscript(pv->peers, owner); if (!peer) { /*DPRINT(("pv_update: no variables for player %d\n", owner)); */ return dp_RES_OK; } /*DPRINT(("pv_update: peer->dirty is %d for player %d\n", peer->dirty, owner));*/ /* If it's time to start a new cycle, do it. */ if (pv->cur_key_index == -1) { if (pv->new_ndests > 0) { /* New hosts have been added since last cycle. */ /* Start a host update cycle. */ /* Copy new host list. */ pv->cur_ndests = pv->new_ndests; memcpy(pv->cur_dests, pv->new_dests, pv->new_ndests * sizeof(pv->new_dests[0])); /* Reset new host list. */ pv->new_ndests = 0; /* Fill key list with all public keys for this player. */ for (i=j=0; i<peer->vars->n_used && j<dp_PLAYERDATA_NKEYS_MAX; i++) { pe = assoctab_getkey(peer->vars, i); if (!pe) break; /* horrible error */ pvar = (pv_var_t *) &pe->value; if (!(pvar->flags & dp_PLAYERDATA_FLAG_NOFLOOD)) { pv->cur_keys[j++] = pe->key; } } /* Early exit if no public variables. */ if (j == 0) return dp_RES_OK; pv->cur_nkeys = j; DPRINT(("pv_update: starting new host update cycle. nkeys %d, ndests %d\n", pv->cur_nkeys, pv->cur_ndests)); /* Trigger start. */ pv->cur_key_index = 0; pv->cur_offset = 0; } else if (peer->dirty > 0) { /* Varible values have changed since last cycle. */ /* Start a variable update cycle. */ peer->dirty = FALSE; DPRINT(("pv_update: Clearing peer->dirty for player %d\n", owner)); /* Set host list to 'all other hosts in game'. */ pv->cur_ndests = dp_getBroadcastHdls(pv->dp, pv->cur_dests); /* Fill key list with all dirty variables. Mark them clean. */ for (i=j=0; i<peer->vars->n_used && j<dp_PLAYERDATA_NKEYS_MAX; i++) { pe = assoctab_getkey(peer->vars, i); if (!pe) break; /* horrible error */ pvar = (pv_var_t *) &pe->value; if ((pvar->flags & dp_PLAYERDATA_FLAG_DIRTY) && !(pvar->flags & dp_PLAYERDATA_FLAG_NOFLOOD)) { pv->cur_keys[j++] = pe->key; pvar->flags &= ~dp_PLAYERDATA_FLAG_DIRTY; } } /* Early exit if no other hosts in game (after clearing dirty!). */ if (pv->cur_ndests <= 0) return dp_RES_OK; /* Early exit if no dirty public variables. */ if (j == 0) return dp_RES_OK; pv->cur_nkeys = j; DPRINT(("pv_update: starting new variable update cycle. nkeys %d, ndests %d\n", pv->cur_nkeys, pv->cur_ndests)); /* Trigger start. */ pv->cur_key_index = 0; pv->cur_offset = 0; } } /* Are we in the middle of an update? */ if (pv->cur_key_index == -1) return dp_RES_OK; /* No. */ /* Get a pointer to the variable we're working on. Make sure it's * still there, still clean, and still needs data transferred. */ do { pvar = (pv_var_t *)assoctab_subscript(peer->vars, pv->cur_keys[pv->cur_key_index]); /* Has it been deleted or changed or finished? */ if (!pvar || (pvar->flags & dp_PLAYERDATA_FLAG_DIRTY) || (pvar->len <= pv->cur_offset)) { DPRINT(("pv_update: pvar %p, flags %x; advancing to next var\n", pvar, pvar?pvar->flags:0x666)); /* Yes. Just advance to the next variable. */ pv->cur_key_index++; pv->cur_offset = 0; if (pv->cur_key_index >= pv->cur_nkeys) { /* That was the last variable. The cycle is over. */ pv->cur_key_index = -1; DPRINT(("pv_update: cycle over\n")); return dp_RES_OK; } pvar = NULL; } } while (!pvar); /* Send the current chunk of the current variable. */ if (pv->cur_offset == 0) { dp_packetType_t *tag = (dp_packetType_t *)buf; pv_playerData_initial_packet_t *body = (pv_playerData_initial_packet_t *)(buf + sizeof(dp_packetType_t)); void *payload = ((char *)body) + sizeof(pv_playerData_initial_packet_t); /* Send an initial chunk. */ len = pvar->len; if (len > pv_PLAYERDATA_INITIAL_MAXLEN) len = pv_PLAYERDATA_INITIAL_MAXLEN; *tag = pv_PLAYERDATA_INITIAL_PACKET_ID; body->len = pvar->len; body->id = owner; body->flags = (short) pvar->flags; body->key = pvar->key; body->crc = pvar->crc; /* call dpSwapPvUpdateInitial to byte swap body */ dpSwapPvUpdateInitial(body); memcpy(payload, pvar->buf, len); hdrlen = sizeof(dp_packetType_t)+sizeof(pv_playerData_initial_packet_t); } else { dp_packetType_t *tag = (dp_packetType_t *)buf; char *pastTag = buf + sizeof(dp_packetType_t); pv_playerData_body_packet_t *body = (pv_playerData_body_packet_t *)pastTag; void *payload = ((char *)body) + sizeof(pv_playerData_body_packet_t); len = pvar->len - pv->cur_offset; if (len > pv_PLAYERDATA_BODY_MAXLEN) len = pv_PLAYERDATA_BODY_MAXLEN; #ifndef __MWERKS__ assert(len>0); #endif *tag = pv_PLAYERDATA_BODY_PACKET_ID; body->id = owner; /* call dpSwapPvUpdate to byte swap body */ dpSwapPvUpdate(body); memcpy(payload, (char *)(pvar->buf)+pv->cur_offset, len); hdrlen = sizeof(dp_packetType_t)+sizeof(pv_playerData_body_packet_t); } err = dpio_put_reliable(pv->dp->dpio, pv->cur_dests, pv->cur_ndests, buf, len + hdrlen, &errHdl); /* Estimate the bandwidth used by this send. */ interval = (pv->dp->clocksPerSec * (len + hdrlen)) / pv_BYTES_PER_SEC; pv->next_send = pv->dp->now + interval; DPRINT(("pv_update: Sent key %d off %d len %d to %d hosts; result %d, errHdl %d; next send in %d tix.\n", pv->cur_keys[pv->cur_key_index], pv->cur_offset, len, pv->cur_ndests, err, errHdl, interval)); if (err == dp_RES_OK) pv->cur_offset += len; else if (err != dp_RES_FULL) DPRINT(("pv_update: serious send problem: dpio_put_reliable returned %d\n", err)); return err; }
DWORD WINAPI ProcessPlayingNotes( LPVOID parameter) { DeviceInfo* device_info = (DeviceInfo*) parameter; NTSTATUS status; IO_STATUS_BLOCK io_status_block; DWORD arp_notes; DPRINT("Note processing started\n"); /* We lock the note list only while accessing it */ #ifdef CONTINUOUS_NOTES while ( WaitForSingleObject(the_device->work_available, INFINITE), !device_info->terminate_thread ) #endif { NoteNode* node; /* Number of notes being arpeggiated */ arp_notes = 1; EnterCriticalSection(&device_lock); /* Calculate how much time to allocate to each playing note */ DPRINT("%d notes active\n", (int) device_info->playing_notes_count); node = device_info->note_list; while ( ( node != NULL ) && ( arp_notes <= POLYPHONY ) ) { BEEP_SET_PARAMETERS beep_data; DWORD actually_playing = 0; double frequency = node->note; DPRINT("playing..\n"); frequency = frequency / 12; frequency = pow(2, frequency); frequency = 8.1758 * frequency; if (device_info->playing_notes_count > POLYPHONY) actually_playing = POLYPHONY; else actually_playing = device_info->playing_notes_count; DPRINT("Frequency %f\n", frequency); // TODO beep_data.Frequency = (DWORD) frequency; beep_data.Duration = TIMESLICE_SIZE / actually_playing; /* device_info->playing_notes_count; */ status = NtDeviceIoControlFile(device_info->kernel_device, NULL, NULL, NULL, &io_status_block, IOCTL_BEEP_SET, &beep_data, sizeof(BEEP_SET_PARAMETERS), NULL, 0); if ( ! NT_SUCCESS(status) ) { DPRINT("ERROR %d\n", (int) GetLastError()); } SleepEx(beep_data.Duration, TRUE); if ( device_info->refresh_notes ) { device_info->refresh_notes = FALSE; break; } arp_notes ++; node = node->next; } LeaveCriticalSection(&device_lock); } return 0; }
MMRESULT OpenDevice( DeviceInfo** private_data, MIDIOPENDESC* open_desc, DWORD flags) { NTSTATUS status; HANDLE heap; HANDLE kernel_device; UNICODE_STRING beep_device_name; OBJECT_ATTRIBUTES attribs; IO_STATUS_BLOCK status_block; /* One at a time.. */ if ( the_device ) { DPRINT("Already allocated\n"); return MMSYSERR_ALLOCATED; } /* Make the device name into a unicode string and open it */ RtlInitUnicodeString(&beep_device_name, L"\\Device\\Beep"); InitializeObjectAttributes(&attribs, &beep_device_name, 0, NULL, NULL); status = NtCreateFile(&kernel_device, FILE_READ_DATA | FILE_WRITE_DATA, &attribs, &status_block, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN_IF, 0, NULL, 0); if ( ! NT_SUCCESS(status) ) { DPRINT("Could not connect to BEEP device - %d\n", (int) GetLastError()); return MMSYSERR_ERROR; } DPRINT("Opened!\n"); /* Allocate and initialize the device info */ heap = GetProcessHeap(); the_device = HeapAlloc(heap, HEAP_ZERO_MEMORY, sizeof(DeviceInfo)); if ( ! the_device ) { DPRINT("Out of memory\n"); return MMSYSERR_NOMEM; } /* Initialize */ the_device->kernel_device = kernel_device; the_device->playing_notes_count = 0; the_device->note_list = NULL; the_device->thread_handle = 0; the_device->terminate_thread = FALSE; the_device->running_status = 0; // TODO the_device->mme_handle = (HDRVR) open_desc->hMidi; the_device->callback = open_desc->dwCallback; the_device->instance = open_desc->dwInstance; the_device->flags = flags; /* Store the pointer in the user data */ *private_data = the_device; /* This is threading-related code */ #ifdef CONTINUOUS_NOTES the_device->work_available = CreateEvent(NULL, TRUE, FALSE, NULL); if ( ! the_device->work_available ) { DPRINT("CreateEvent failed\n"); HeapFree(heap, 0, the_device); return MMSYSERR_NOMEM; } the_device->thread_handle = CreateThread(NULL, 0, ProcessPlayingNotes, (PVOID) the_device, 0, NULL); if ( ! the_device->thread_handle ) { DPRINT("CreateThread failed\n"); CloseHandle(the_device->work_available); HeapFree(heap, 0, the_device); return MMSYSERR_NOMEM; } #endif /* Now we call the client application to say the device is open */ DPRINT("Sending MOM_OPEN\n"); DPRINT("Success? %d\n", (int) CallClient(the_device, MOM_OPEN, 0, 0)); return MMSYSERR_NOERROR; }
void MAVMissionOutput_40hz(void) { #if (FLIGHT_PLAN_TYPE == FP_WAYPOINTS) // LOGO_WAYPOINTS cannot be uploaded / downloaded vect3_32t wp; if (mavlink_flags.mavlink_send_waypoint_reached == 1) { mavlink_flags.mavlink_send_waypoint_reached = 0; mavlink_msg_mission_item_reached_send(MAVLINK_COMM_0, mav_waypoint_reached); } if (mavlink_flags.mavlink_send_waypoint_changed == 1) { mavlink_flags.mavlink_send_waypoint_changed = 0; mavlink_msg_mission_current_send(MAVLINK_COMM_0, mav_waypoint_changed); } //static inline void mavlink_msg_mission_item_reached_send(mavlink_channel_t chan, uint16_t seq) //static inline void mavlink_msg_mission_current_send(mavlink_channel_t chan, uint16_t seq) // CHECK WHETHER WAYPOINT PROTOCOL HAS TIMED OUT WAITING ON A RESPONSE if (mavlink_waypoint_timeout <= 0) { if (mavlink_flags.mavlink_sending_waypoints || mavlink_flags.mavlink_receiving_waypoints) { //send_text((uint8_t *)"Timeout on waypoint protocol.\r\n"); DPRINT("Timeout on waypoint protocol.\r\n"); } mavlink_flags.mavlink_sending_waypoints = false; mavlink_flags.mavlink_receiving_waypoints = false; } // if (mavlink_flags.mavlink_receiving_waypoints == 1) if (mavlink_flags.mavlink_request_specific_waypoint == 1) { DPRINT("requesting waypoint: %u\r\n", waypoint_request_i); //mavlink_flags.waypoint_request_i = 0; //static inline void mavlink_msg_mission_request_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, uint16_t seq) mavlink_msg_mission_request_send(MAVLINK_COMM_0, mavlink_waypoint_dest_sysid, mavlink_waypoint_dest_compid, waypoint_request_i); mavlink_flags.mavlink_request_specific_waypoint = 0; } // SEND NUMBER OF WAYPOINTS IN WAYPOINTS LIST if (mavlink_flags.mavlink_send_waypoint_count == 1) { int16_t number_of_waypoints = waypoint_count(); //send_text((uint8_t *)"Sending waypoint count\r\n"); DPRINT("Sending waypoint count: %u\r\n", number_of_waypoints); mavlink_msg_mission_count_send(MAVLINK_COMM_0, mavlink_waypoint_dest_sysid, mavlink_waypoint_dest_compid, number_of_waypoints); mavlink_flags.mavlink_send_waypoint_count = 0; } // SEND DETAILS OF A SPECIFIC WAYPOINT if (mavlink_flags.mavlink_send_specific_waypoint == 1) { //send_text((uint8_t *)"Time to send a specific waypoint\r\n"); DPRINT("Time to send a specific waypoint: %u\r\n", mavlink_waypoint_requested_sequence_number); // mavlink_msg_mission_item_send(mavlink_channel_t chan, uint8_t target_system, uint8_t target_component, // uint16_t seq, uint8_t frame, uint16_t command, uint8_t current, uint8_t autocontinue, // float param1, float param2, float param3, float param4, // float x, float y, float z) //BUILDING //struct waypoint3D { int32_t x; int32_t y; int16_t z; }; // struct waypoint3D getWaypoint3D(uint16_t wp); // struct waypoint3D wp; // wp = getWaypoint3D(mavlink_waypoint_requested_sequence_number); wp = getWaypoint3D(mavlink_waypoint_requested_sequence_number); //float lat_float, lon_float, alt_float = 0.0; //uint32_t accum_long = IMUlocationy._.W1 + (lat_origin.WW / 90); // meters North from Equator //lat_float = (float)((accum_long * 90) / 10000000.0); // degrees North from Equator //lon_float = (float)((float) lon_origin.WW + ((float)(IMUlocationx._.W1) * 90.0) / (float)(cos_lat / 16384.0)) / 10000000.0; //extern struct relWaypointDef wp_to_relative(struct waypointDef wp); //struct relWaypointDef current_waypoint = wp_to_relative(waypoints[waypointIndex]); //alt_float = ((float)(IMUlocationz._.W1)) + (float)(alt_origin.WW / 100.0); mavlink_msg_mission_item_send(MAVLINK_COMM_0, mavlink_waypoint_dest_sysid, mavlink_waypoint_dest_compid, \ mavlink_waypoint_requested_sequence_number, mavlink_waypoint_frame, MAV_CMD_NAV_WAYPOINT, mavlink_waypoint_current, true, \ 0.0, 0.0, 0.0, 0.0, \ (float)wp.y / 10000000.0, (float)wp.x / 10000000.0, wp.z); DPRINT("waypoint %f %f %f\r\n", (double)wp.y / 10000000.0, (double)wp.x / 10000000.0, (double)wp.z); mavlink_flags.mavlink_send_specific_waypoint = 0; } if (mavlink_waypoint_timeout > 0) mavlink_waypoint_timeout--; #endif // (FLIGHT_PLAN_TYPE == FP_WAYPOINTS) /* // Acknowledge a command if flaged to do so. if (mavlink_send_command_ack == true) { mavlink_msg_command_ack_send(MAVLINK_COMM_0, mavlink_command_ack_command, mavlink_command_ack_result); mavlink_send_command_ack = false; } */ }
static inline void MissionRequest(mavlink_message_t* handle_msg) { mavlink_mission_request_t packet; //send_text((uint8_t*)"waypoint request\r\n"); //DPRINT("mission request\r\n"); // Check if in sending waypoint mode ... if (!mavlink_flags.mavlink_sending_waypoints) { DPRINT("mission request not valid, no longer sending\r\n"); return; } // decode mavlink_msg_mission_request_decode(handle_msg, &packet); if (mavlink_check_target(packet.target_system, packet.target_component)) return; mavlink_waypoint_timeout = MAVLINK_WAYPOINT_TIMEOUT; mavlink_waypoint_requested_sequence_number = packet.seq; DPRINT("mission request: packet.seq %u\r\n", packet.seq); mavlink_waypoint_frame = MAV_FRAME_GLOBAL; // reference frame if (mavlink_waypoint_requested_sequence_number == waypointIndex) { mavlink_waypoint_current = true; } else { mavlink_waypoint_current = false; } // send waypoint mavlink_flags.mavlink_send_specific_waypoint = 1; /************** Not converted to MAVLink wire protocol 1.0 yet *******************/ //uint8_t action = MAV_ACTION_NAVIGATE; // action //uint8_t orbit_direction = 0; // clockwise(0), counter-clockwise(1) //float orbit = 0; // loiter radius //float param1 = 0, param2 = 0; //switch(tell_command.id) //{ //case CMD_WAYPOINT: // navigate //action = MAV_ACTION_NAVIGATE; // action //break; // case CMD_LOITER_TIME: // loiter //orbit = get(PARAM_WP_RADIUS); // XXX setting loiter radius as waypoint acceptance radius //action = MAV_ACTION_LOITER; // action //param1 = get(PARAM_WP_RADIUS); //param2 = tell_command.p1*100; // loiter time //break; // case CMD_TAKEOFF: // takeoff //action = MAV_ACTION_TAKEOFF; //break; //case CMD_LAND: // land //action = MAV_ACTION_LAND; //break; //defaut: //gcs.send_text("command not handled"); //break; //} // time that the mav should loiter in milliseconds //uint8_t current = 0; // 1 (true), 0 (false) //if (packet.seq == get(PARAM_WP_INDEX)) current = 1; //float yaw_dir = 0; // yaw orientation in radians, 0 = north XXX: what does this do? //uint8_t autocontinue = 1; // 1 (true), 0 (false) //float x = tell_command.lng/1.0e7; // local (x), global (longitude) //float y = tell_command.lat/1.0e7; // local (y), global (latitude) //float z = tell_command.alt/1.0e2; // local (z), global (altitude) // note XXX: documented x,y,z order does not match with gps raw //mavlink_msg_waypoint_send(chan,handle_msg->sysid, //handle_msg->compid,packet.seq,frame,action, //orbit,orbit_direction,param1,param2,current,x,y,z,yaw_dir,autocontinue); // update last waypoint comm stamp //global_data.waypoint_timelast_send = millis(); }
static inline void MissionItem(mavlink_message_t* handle_msg) { int16_t flags; struct waypoint3D wp; mavlink_mission_item_t packet; //send_text((uint8_t*)"waypoint\r\n"); // DPRINT("mission item\r\n"); // Check if receiving waypoint if (!mavlink_flags.mavlink_receiving_waypoints) return; // decode mavlink_msg_mission_item_decode(handle_msg, &packet); if (mavlink_check_target(packet.target_system, packet.target_component)) return; DPRINT("mission item: %u\r\n", packet.seq); // check if this is the requested waypoint if (packet.seq != waypoint_request_i) return; // store waypoint //uint8_t loadAction = 0; // 0 insert in list, 1 exec now switch (packet.frame) { case MAV_FRAME_GLOBAL: { // DPRINT("FRAME_GLOBAL\r\n"); //struct waypoint3D { int32_t x; int32_t y; int16_t z; }; //struct waypointDef { struct waypoint3D loc; int16_t flags; struct waypoint3D viewpoint; }; // DPRINT("packet.x %f packet.y %f packet.z %f\r\n", packet.x, packet.y, packet.z); //tell_command.lng = 1.0e7*packet.x; //tell_command.lat = 1.0e7*packet.y; //tell_command.alt = packet.z*1.0e2; // MatrixPilot uses X & Y in reverse to QGC wp.x = packet.y * 1.0e7; wp.y = packet.x * 1.0e7; wp.z = packet.z; flags = F_ABSOLUTE; break; } case MAV_FRAME_LOCAL_NED: // local (relative to home position) { DPRINT("FRAME_LOCAL - not implemented\r\n"); //tell_command.lng = 1.0e7*ToDeg(packet.x/ //(radius_of_earth*cos(ToRad(home.lat/1.0e7)))) + home.lng; //tell_command.lat = 1.0e7*ToDeg(packet.y/radius_of_earth) + home.lat; //tell_command.alt = -packet.z*1.0e2 + home.alt; break; } } // defaults //tell_command.id = CMD_BLANK; // Currently F can be set to: F_NORMAL, or any combination of: // F_ABSOLUTE - Waypoints are Relative by default, unless F_ABSOLUTE is specified. // // F_TAKEOFF - More quickly gain altitude at takeoff. // F_INVERTED - Navigate to this waypoint with the plane upside down. (only if STABILIZE_INVERTED_FLIGHT is set to 1 in options.h) // F_HOVER - Hover the plane until reaching this waypoint. (only if STABILIZE_HOVER is set to 1 in options.h) // NOTE: while hovering, no navigation is performed, and throttle is under manual control. // F_LOITER - After reaching this waypoint, continue navigating towards this same waypoint. Repeat until leaving waypoint mode. // F_TRIGGER - Trigger an action to happen when this waypoint leg starts. (See the Trigger Action section of the options.h file.) // F_ALTITUDE_GOAL - Climb or descend to the given altitude, then continue to the next waypoint. // F_CROSS_TRACK - Navigate using cross-tracking. Best used for longer waypoint legs. // F_LAND - Navigate towards this waypoint with the throttle off. switch (packet.command) { case MAV_CMD_NAV_TAKEOFF: DPRINT("NAV_TAKEOFF\r\n"); //tell_command.id = CMD_TAKEOFF; flags |= F_TAKEOFF; break; case MAV_CMD_NAV_LAND: DPRINT("NAV_LAND\r\n"); //tell_command.id = CMD_LAND; flags |= F_LAND; break; case MAV_CMD_NAV_WAYPOINT: // DPRINT("NAV_WAYPOINT\r\n"); //tell_command.id = CMD_WAYPOINT; break; case MAV_CMD_NAV_LOITER_UNLIM: // DPRINT("NAV_LOITER\r\n"); //tell_command.id = CMD_LOITER_TIME; //tell_command.p1 = packet.param2/1.0e2; break; } // save waypoint add_waypoint(wp, flags); //set_wp_with_index(tell_command, packet.seq); // update waypoint receiving state machine //global_data.waypoint_timelast_receive = millis(); mavlink_waypoint_timeout = MAVLINK_WAYPOINT_TIMEOUT; waypoint_request_i++; if (waypoint_request_i == get(PARAM_WP_TOTAL)) { uint8_t type = 0; // ok (0), error(1) //gcs.send_text("flight plane received"); DPRINT("flight plan received\r\n"); mavlink_msg_mission_ack_send(MAVLINK_COMM_0, handle_msg->sysid, handle_msg->compid, type); mavlink_flags.mavlink_receiving_waypoints = false; // XXX ignores waypoint radius for individual waypoints, can // only set WP_RADIUS parameter // send MAVLINK_MSG_ID_MISSION_ACK ? } else { mavlink_flags.mavlink_request_specific_waypoint = 1; } }
int tre_regncomp_l(regex_t *preg, const char *regex, size_t n, int cflags, locale_t loc) { int ret; #if TRE_WCHAR tre_char_t *wregex; size_t wlen; wregex = xmalloc(sizeof(tre_char_t) * (n + 1)); if (wregex == NULL) return REG_ESPACE; FIX_LOCALE(loc); /* If the current locale uses the standard single byte encoding of characters, we don't do a multibyte string conversion. If we did, many applications which use the default locale would break since the default "C" locale uses the 7-bit ASCII character set, and all characters with the eighth bit set would be considered invalid. */ #if TRE_MULTIBYTE if (TRE_MB_CUR_MAX_L(loc) == 1) #endif /* TRE_MULTIBYTE */ { unsigned int i; const unsigned char *str = (const unsigned char *)regex; tre_char_t *wstr = wregex; for (i = 0; i < n; i++) *(wstr++) = *(str++); wlen = n; } #if TRE_MULTIBYTE else { size_t consumed; tre_char_t *wcptr = wregex; #ifdef HAVE_MBSTATE_T mbstate_t state; memset(&state, '\0', sizeof(state)); #endif /* HAVE_MBSTATE_T */ while (n > 0) { consumed = tre_mbrtowc_l(wcptr, regex, n, &state, loc); switch (consumed) { case 0: if (*regex == '\0') consumed = 1; else { xfree(wregex); return REG_BADPAT; } break; case (size_t)-1: case (size_t)-2: DPRINT(("mbrtowc: error %d: %s.\n", errno, strerror(errno))); xfree(wregex); return REG_ILLSEQ; } regex += consumed; n -= consumed; wcptr++; } wlen = wcptr - wregex; } #endif /* TRE_MULTIBYTE */ wregex[wlen] = L'\0'; ret = tre_compile(preg, wregex, wlen, cflags, loc); xfree(wregex); #else /* !TRE_WCHAR */ FIX_LOCALE(loc); ret = tre_compile(preg, (const tre_char_t *)regex, n, cflags, loc); #endif /* !TRE_WCHAR */ return ret; }
NTSTATUS NTAPI VfatShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp) { NTSTATUS Status; PLIST_ENTRY ListEntry; PDEVICE_EXTENSION DeviceExt; ULONG eocMark; DPRINT("VfatShutdown(DeviceObject %p, Irp %p)\n",DeviceObject, Irp); FsRtlEnterFileSystem(); /* FIXME: block new mount requests */ if (DeviceObject == VfatGlobalData->DeviceObject) { Irp->IoStatus.Status = STATUS_SUCCESS; ExAcquireResourceExclusiveLite(&VfatGlobalData->VolumeListLock, TRUE); ListEntry = VfatGlobalData->VolumeListHead.Flink; while (ListEntry != &VfatGlobalData->VolumeListHead) { DeviceExt = CONTAINING_RECORD(ListEntry, VCB, VolumeListEntry); ListEntry = ListEntry->Flink; ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE); if (DeviceExt->VolumeFcb->Flags & VCB_CLEAR_DIRTY) { /* set clean shutdown bit */ Status = GetNextCluster(DeviceExt, 1, &eocMark); if (NT_SUCCESS(Status)) { eocMark |= DeviceExt->CleanShutBitMask; if (NT_SUCCESS(WriteCluster(DeviceExt, 1, eocMark))) DeviceExt->VolumeFcb->Flags &= ~VCB_IS_DIRTY; } } Status = VfatFlushVolume(DeviceExt, DeviceExt->VolumeFcb); if (NT_SUCCESS(Status)) { Status = VfatDiskShutDown(DeviceExt); if (!NT_SUCCESS(Status)) DPRINT1("VfatDiskShutDown failed, status = %x\n", Status); } else { DPRINT1("VfatFlushVolume failed, status = %x\n", Status); } ExReleaseResourceLite(&DeviceExt->DirResource); /* FIXME: Unmount the logical volume */ if (!NT_SUCCESS(Status)) Irp->IoStatus.Status = Status; } ExReleaseResourceLite(&VfatGlobalData->VolumeListLock); /* FIXME: Free all global acquired resources */ Status = Irp->IoStatus.Status; } else { Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST; Status = STATUS_INVALID_DEVICE_REQUEST; } Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); FsRtlExitFileSystem(); return(Status); }
int GGI_vgl_setmode(ggi_visual *vis, ggi_mode *tm) { struct vgl_priv *priv = VGL_PRIV(vis); ggi_graphtype gt = tm->graphtype; video_info_t modeinfo; unsigned long modenum = 0; char sugname[GGI_MAX_APILEN]; char args[GGI_MAX_APILEN]; int err = 0; int id, i; int pixelBytes; err = GGI_vgl_checkmode(vis, tm); if (err) return err; /* reset the modeinfo structure as expected by query_mode */ memset(&modeinfo, 0, sizeof(modeinfo)); switch(gt) { case GT_1BIT : modeinfo.vi_depth = 1; pixelBytes = 1; break; case GT_4BIT : modeinfo.vi_depth = 4; pixelBytes = 1; break; case GT_8BIT : modeinfo.vi_depth = 8; pixelBytes = 1; break; case GT_16BIT: modeinfo.vi_depth = 16; pixelBytes = 2; break; case GT_32BIT: modeinfo.vi_depth = 32; pixelBytes = 4; break; /* Unsupported mode depths */ case GT_15BIT: case GT_24BIT: default: return GGI_ENOMATCH; } modeinfo.vi_width = tm->visible.x; modeinfo.vi_height = tm->visible.y; /* XXX should be added to libvgl */ if (ioctl(0, FBIO_FINDMODE, &modeinfo)) return -1; DPRINT("Setting VGLlib mode %d (0x%x)\n", modeinfo.vi_mode, modeinfo.vi_mode); /* Terminate any current mode before initialising another */ if (priv->vgl_init_done) { priv->vgl_init_done = 0; VGLEnd(); } /* XXX should be in VGL */ if ((modeinfo.vi_mode >= M_B40x25) && (modeinfo.vi_mode <= M_VGA_M90x60)) modenum = _IO('S', modeinfo.vi_mode); if ((modeinfo.vi_mode >= M_TEXT_80x25) && (modeinfo.vi_mode <= M_TEXT_132x60)) modenum = _IO('S', modeinfo.vi_mode); if ((modeinfo.vi_mode >= M_VESA_CG640x400) && (modeinfo.vi_mode <= M_VESA_FULL_1280)) modenum = _IO('V', modeinfo.vi_mode - M_VESA_BASE); if ((err = VGLInit(modenum)) != 0) { DPRINT("display-vgl: setting mode 0x%x failed with error %d\n", modeinfo.vi_mode, err); return GGI_EFATAL; } priv->vgl_init_done = 1; if (priv->vgl_use_db) { _GGI_vgl_freedbs(vis); /* Set up DirectBuffer(s) */ for (i = 0; i<tm->frames; i++) { if (LIBGGI_FB_SIZE(tm) > (unsigned)(VGLDisplay->Xsize*VGLDisplay->Ysize* pixelBytes)) { fprintf(stderr, "display-vgl: framebuffer too large! (%d > %d*%d*%d)\n", LIBGGI_FB_SIZE(tm), VGLDisplay->Xsize, VGLDisplay->Ysize, pixelBytes); return GGI_ENOMEM; } _ggi_db_add_buffer(LIBGGI_APPLIST(vis), _ggi_db_get_new()); LIBGGI_APPBUFS(vis)[i]->frame = i; LIBGGI_APPBUFS(vis)[i]->type = GGI_DB_NORMAL | GGI_DB_SIMPLE_PLB; LIBGGI_APPBUFS(vis)[i]->read = VGLDisplay->Bitmap; LIBGGI_APPBUFS(vis)[i]->write = VGLDisplay->Bitmap; LIBGGI_APPBUFS(vis)[i]->layout = blPixelLinearBuffer; LIBGGI_APPBUFS(vis)[i]->buffer.plb.stride = GT_ByPPP(tm->virt.x, tm->graphtype); } } /* Save mode info returned by the VESA driver */ bcopy(&modeinfo, &priv->modeinfo, sizeof(priv->modeinfo)); /* Palette */ if (vis->palette) { free(vis->palette); vis->palette = NULL; } if (priv->savepalette) { free(priv->savepalette); priv->savepalette = NULL; } if (GT_SCHEME(tm->graphtype) == GT_PALETTE) { int len = 1 << GT_DEPTH(tm->graphtype); vis->palette = malloc(len * sizeof(ggi_color)); if (vis->palette == NULL) return GGI_EFATAL; priv->savepalette = malloc(sizeof(int) * (len*3)); if (priv->savepalette == NULL) return GGI_EFATAL; /* Set an initial palette */ ggiSetColorfulPalette(vis); } /* Set up pixel format */ memset(LIBGGI_PIXFMT(vis), 0, sizeof(ggi_pixelformat)); LIBGGI_PIXFMT(vis)->size = GT_SIZE(gt); LIBGGI_PIXFMT(vis)->depth = GT_DEPTH(gt); switch (GT_SCHEME(gt)) { case GT_PALETTE: case GT_GREYSCALE: LIBGGI_PIXFMT(vis)->clut_mask = (1 << GT_DEPTH(gt)) - 1; break; case GT_TRUECOLOR: DPRINT_MODE("display-vgl: RGB %d:%d:%d offsets %d:%d:%d\n", priv->modeinfo.vi_pixel_fsizes[VGL_RED_INDEX], priv->modeinfo.vi_pixel_fsizes[VGL_GREEN_INDEX], priv->modeinfo.vi_pixel_fsizes[VGL_BLUE_INDEX], priv->modeinfo.vi_pixel_fields[VGL_RED_INDEX], priv->modeinfo.vi_pixel_fields[VGL_GREEN_INDEX], priv->modeinfo.vi_pixel_fields[VGL_BLUE_INDEX]); LIBGGI_PIXFMT(vis)->red_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_RED_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_RED_INDEX]; LIBGGI_PIXFMT(vis)->green_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_GREEN_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_GREEN_INDEX]; LIBGGI_PIXFMT(vis)->blue_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_BLUE_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_BLUE_INDEX]; break; case GT_TEXT: /* Assumes VGA text */ LIBGGI_PIXFMT(vis)->texture_mask = 0x00ff; LIBGGI_PIXFMT(vis)->fg_mask = 0x0f00; LIBGGI_PIXFMT(vis)->bg_mask = 0xf000; break; } _ggi_build_pixfmt(LIBGGI_PIXFMT(vis)); memcpy(LIBGGI_MODE(vis),tm,sizeof(ggi_mode)); _ggiZapMode(vis, 0); for(id = 1; 0 == GGI_vgl_getapi(vis, id, sugname, args); id++) { if (_ggiOpenDL(vis, _ggiGetConfigHandle(), sugname, args, NULL)) { fprintf(stderr,"display-vgl: Can't open the %s (%s) library.\n", sugname, args); return GGI_EFATAL; } else { DPRINT("Success in loading %s (%s)\n", sugname, args); } } if (!priv->vgl_use_db) { vis->opdraw->putpixel = GGI_vgl_putpixel; vis->opdraw->putpixel_nc = GGI_vgl_putpixel_nc; vis->opdraw->getpixel = GGI_vgl_getpixel; vis->opdraw->drawpixel = GGI_vgl_drawpixel; vis->opdraw->drawpixel_nc = GGI_vgl_drawpixel_nc; vis->opdraw->drawhline = GGI_vgl_drawhline; vis->opdraw->drawhline_nc = GGI_vgl_drawhline_nc; vis->opdraw->drawvline = GGI_vgl_drawvline; vis->opdraw->drawvline_nc = GGI_vgl_drawvline_nc; vis->opdraw->drawbox = GGI_vgl_drawbox; vis->opdraw->drawline = GGI_vgl_drawline; vis->opdraw->puthline = GGI_vgl_puthline; vis->opdraw->putbox = GGI_vgl_putbox; } else { vis->opdraw->setorigin = GGI_vgl_setorigin; } if (GT_SCHEME(tm->graphtype) == GT_PALETTE) { vis->opcolor->setpalvec = GGI_vgl_setpalvec; } if(priv->vgl_use_db) { for(i = 0; i<tm->frames; i++) LIBGGI_APPBUFS(vis)[i]->buffer.plb.pixelformat = LIBGGI_PIXFMT(vis); } ggiIndicateChange(vis, GGI_CHG_APILIST); return 0; }
MMRESULT PlayNote( DeviceInfo* device_info, UCHAR note, UCHAR velocity) { HANDLE heap = GetProcessHeap(); NoteNode* node; DPRINT("PlayNote\n"); if ( velocity == 0 ) { DPRINT("Zero velocity\n"); /* Velocity zero is effectively a "note off" */ StopNote(device_info, note); } else { /* Start playing the note */ NoteNode* new_node; EnterCriticalSection(&device_lock); node = device_info->note_list; while ( node != NULL ) { #ifndef ALLOW_DUPLICATE_NOTES if ( ( node->note == note ) && ( velocity > 0 ) ) { /* The note is already playing - do nothing */ DPRINT("Duplicate note playback request ignored\n"); LeaveCriticalSection(&device_lock); return MMSYSERR_NOERROR; } #endif node = node->next; } new_node = HeapAlloc(heap, HEAP_ZERO_MEMORY, sizeof(NoteNode)); if ( ! new_node ) { LeaveCriticalSection(&device_lock); return MMSYSERR_NOMEM; } new_node->note = note; new_node->velocity = velocity; /* Prepend to the playing notes list. If exceeding polyphony, remove the oldest note (which will be at the tail.) */ if ( device_info->note_list ) device_info->note_list->previous = new_node; new_node->next = device_info->note_list; new_node->previous = NULL; device_info->note_list = new_node; device_info->playing_notes_count ++; /* if ( device_info->playing_notes_count > POLYPHONY ) { ASSERT(tail_node); DPRINT("Polyphony exceeded\n"); tail_node->previous->next = NULL; HeapFree(heap, 0, tail_node); device_info->playing_notes_count --; } */ #ifdef CONTINUOUS_NOTES SetEvent(device_info->work_available); #endif LeaveCriticalSection(&device_lock); DPRINT("Note started - now playing %d notes\n", (int) device_info->playing_notes_count); device_info->refresh_notes = TRUE; } #ifndef CONTINUOUS_NOTES ProcessPlayingNotes((PVOID) device_info); #endif return MMSYSERR_NOERROR; }
void read_xmms_config() { int count; /*char tempname[100];*/ char *tempname = (char *)malloc(sizeof(char)*100); gchar *path; gchar *ext; mcs_handle_t *config; DPRINT (__DEBUG_GENERAL__,"Starting to read xmms config"); // empty cover search list, the plugin is probably initialized twice by the user g_slist_free (cdcover_config.cover_searchpaths); cdcover_config.cover_searchpaths = NULL; // empty extension search list, the plugin is probably initialized twice by the user g_slist_free (cdcover_config.cover_extensions); cdcover_config.cover_extensions = NULL; config = aud_cfg_db_open (); if (config) { // Window position aud_cfg_db_get_bool (config,PLUGIN_NAME,"savewindowpos",&cdcover_config.save_window_pos); aud_cfg_db_get_int (config,PLUGIN_NAME,"windowposx",&cdcover_config.winpos_x); aud_cfg_db_get_int (config,PLUGIN_NAME,"windowposy",&cdcover_config.winpos_y); // Aspect ratio aud_cfg_db_get_bool (config,PLUGIN_NAME,"aspectratio",&cdcover_config.preserve_aspectratio); // Skin if (!aud_cfg_db_get_string (config,PLUGIN_NAME,"skinpath",&cdcover_config.skin_path)) { cdcover_config.skin_path = NULL; } // Read in the paths sprintf (tempname,"path1"); count=1; while (aud_cfg_db_get_string (config,PLUGIN_NAME,tempname,&path)) { // save the pointer to this resource string in the list cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path); //printf("Got path '%s' with var %s\n", path, tempname); // construct next path variable count++; sprintf (tempname,"path%d",count); } // Where we able to read any search paths ? if (g_slist_length(cdcover_config.cover_searchpaths)==0) { // Some default paths to start with // Allocate memory, so we can free it on shutdown //printf("No paths found, populating with defaults\n"); gchar *path1 = g_strconcat ("?PATH?/cover.jpg",NULL); gchar *path2 = g_strconcat ("?PATH?/?BASE?.jpg",NULL); gchar *path3 = g_strconcat ("?PATH?/media/?FILENAME?.jpg",NULL); gchar *path4 = g_strconcat ("?PATH?/*.jpg",NULL); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path1); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path2); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path3); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path4); } // Read in the extensions sprintf (tempname,"ext1"); count=1; while (aud_cfg_db_get_string (config,PLUGIN_NAME,tempname,&ext)) { // save the pointer to this resource string in the list cdcover_config.cover_extensions = g_slist_append (cdcover_config.cover_extensions,ext); //printf("Got ext '%s' with var %s\n", ext, tempname); // construct next path variable count++; sprintf (tempname,"ext%d",count); } // Were we able to read any extensions? if (g_slist_length(cdcover_config.cover_extensions)==0) { // Some default extensions to start with // Allocate memory, so we can free it on shutdown //printf("No extensions found, populating with defaults\n"); gchar *ext1 = g_strconcat ("png",NULL); gchar *ext2 = g_strconcat ("jpg",NULL); gchar *ext3 = g_strconcat ("gif",NULL); cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext1); cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext2); cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext3); } // Free config handle aud_cfg_db_close (config); } else { DPRINT (__DEBUG_GENERAL__,"Cannot open config file"); } }
MMRESULT ProcessShortMidiMessage( DeviceInfo* device_info, DWORD message) { DWORD status; DWORD category; DWORD channel; DWORD data1, data2; status = message & 0x000000FF; /* Deal with running status */ if ( status < MIDI_NOTE_OFF ) { status = device_info->running_status; } /* Ensure the status is sane! */ if ( status < MIDI_NOTE_OFF ) { /* It's garbage, ignore it */ return MMSYSERR_NOERROR; } /* Figure out the message category and channel */ category = status & 0xF0; channel = status & 0x0F; /* we don't use this */ data1 = (message & 0x0000FF00) >> 8; data2 = (message & 0x00FF0000) >> 16; DPRINT("0x%x, %d, %d\n", (int) status, (int) data1, (int) data2); /* Filter drums (which are *usually* on channel 10) */ if ( channel == 10 ) { return MMSYSERR_NOERROR; } /* Pass to the appropriate message handler */ switch ( category ) { case MIDI_NOTE_ON : { PlayNote(device_info, data1, data2); break; } case MIDI_NOTE_OFF : { StopNote(device_info, data1); break; } } return MMSYSERR_NOERROR; }
/*-------------------------------------------------------------------------- Process a network message generated by this module on another computer. Note: player deletion should be noticed by some other handler, and should cause a call to pv_deletePlayer(). Large variables will be handled as follows: The buffer is broken into pieces. The first piece is sent with tag pv_PLAYERDATA_INITIAL_PACKET_ID and has a header structure describing the length, owner, and key of the incoming variables. Subsequent pieces are sent with tag pv_PLAYERDATA_BODY_PACKET_ID, and lack headers. When a first piece comes in, it goes into a holding area for that source; When middle or last pieces come in, they are appended to the holding area; When a last piece comes in, the holding area is copied to the real variable area, and the user code is informed. On success, if not the final packet, Returns dp_RES_EMPTY. else, Returns dp_RES_OK, and places a tagged dp_user_playerData_packet_t in buffer. --------------------------------------------------------------------------*/ dp_result_t pv_handlePacket(pv_t *pv, size_t len, void *buf) { dp_packetType_t *tag = (dp_packetType_t *)buf; pv_peer_t *peer; pv_var_t *pvar; dp_result_t err; dpid_t id; #ifdef DPRINTBUFS DPRINT(("pv_handlePacket(pv, %d, ", len)); dprint_buf(buf, len); #endif if (!pv) return dp_RES_BUG; if (*tag == pv_PLAYERDATA_INITIAL_PACKET_ID) { pv_playerData_initial_packet_t *body = (pv_playerData_initial_packet_t *)((char *)buf + sizeof(dp_packetType_t)); void *payload = ((char *)body) + sizeof(pv_playerData_initial_packet_t); size_t datalen = len - sizeof(dp_packetType_t) - sizeof(pv_playerData_initial_packet_t); if (datalen < 1 || datalen > pv_PLAYERDATA_INITIAL_MAXLEN) return dp_RES_BUG; /* call dpSwapPvUpdateInitial to byte swap body */ dpSwapPvUpdateInitial(body); id = body->id; /* Locate the sender's holding area and check for sanity. */ peer = (pv_peer_t *)assoctab_subscript(pv->peers, id); if (!peer) { /* No peer yet. Create one. Hope we can trust id. */ peer = pv_addPlayer(pv, id); if (!peer) { DPRINT(("pv_handlePacket: pv_addPlayer returns NULL\n")); return dp_RES_NOMEM; } } pvar = &peer->incoming; if (peer->allocated < body->len) { void *p = dp_REALLOC(pvar->buf, body->len); if (!p) return dp_RES_NOMEM; pvar->buf = p; peer->allocated = body->len; } /* Clear the holding area & copy this in. */ pvar->key = body->key; pvar->flags = body->flags; pvar->len = body->len; pvar->crc = body->crc; memcpy(pvar->type, body->type, sizeof(pvar->type)); memcpy(pvar->buf, payload, datalen); pvar->offset = datalen; DPRINT(("pv_handlePacket: after 1st packet, offset is %d, len is %d\n", pvar->offset, pvar->len)); } else if (*tag == pv_PLAYERDATA_BODY_PACKET_ID) { pv_playerData_body_packet_t *body = (pv_playerData_body_packet_t *)((char *)buf + sizeof(dp_packetType_t)); void *payload = ((char *)body) + sizeof(pv_playerData_body_packet_t); size_t datalen = len - sizeof(dp_packetType_t) - sizeof(pv_playerData_body_packet_t); if (datalen < 1 || datalen > pv_PLAYERDATA_BODY_MAXLEN) { DPRINT(("pv_handlePacket: datalen\n")); return dp_RES_BUG; } /* call dpSwapPvUpdate to byte swap body */ dpSwapPvUpdate(body); id = body->id; /* Locate the sender's holding area and check for sanity. */ peer = (pv_peer_t *)assoctab_subscript(pv->peers, id); if (!peer) { DPRINT(("pv_handlePacket: no variables for player %d\n", id)); return dp_RES_BAD; } pvar = &peer->incoming; if (peer->allocated < pvar->offset + datalen) { DPRINT(("pv_handlePacket: allocated %d need %d + %d\n", peer->allocated, pvar->offset, datalen)); return dp_RES_BUG; } /* Append to holding area. */ memcpy((char *)pvar->buf + pvar->offset, payload, datalen); pvar->offset += datalen; DPRINT(("pv_handlePacket: after: id %d, key %d, offset %d, len %d\n", id, pvar->key, pvar->offset, pvar->len)); } else return dp_RES_EMPTY; /* no error - but no pv packet recognized */ if (pvar->offset == pvar->len) { /* The variable has arrived! Obey the value change it carries. * Don't echo to other machines! */ long newcrc = dp_crc32((unsigned char *)pvar->buf, pvar->len); DPRINT(("pv_handlePacket: got crc %x\n", newcrc)); if (newcrc != pvar->crc) { DPRINT(("pv_handlePacket: bad crc %x, expected %x!\n", newcrc, pvar->crc)); return dp_RES_BAD; } err = pv_set(pv, id, pvar->key, pvar->len, pvar->buf, dp_PLAYERDATA_FLAG_NOFLOOD); DPRINT(("pv_handlePacket: called pv_set; returning err %d\n", err)); if (err == dp_RES_OK) { dp_user_playerData_packet_t *body = (dp_user_playerData_packet_t *)((char *)buf + sizeof(dp_packetType_t)); /* Notify local players - overwrite buffer with user packet. */ *tag = dp_USER_PLAYERDATA_PACKET_ID; body->len = pvar->len; body->id = id; body->key = pvar->key; body->data = pvar->buf; return dp_RES_OK; } return err; } return dp_RES_EMPTY; }
MMRESULT ProcessLongMidiMessage( DeviceInfo* device_info, MIDIHDR* header) { unsigned int index = 0; UCHAR* midi_bytes = (UCHAR*) header->lpData; unsigned int msg_index = 0; UCHAR msg[3]; /* Initialize the buffer */ msg[0] = msg[1] = msg[2] = 0; if ( ! ( header->dwFlags & MHDR_PREPARED ) ) { DPRINT("Not prepared!\n"); return MIDIERR_UNPREPARED; } DPRINT("Processing %d bytes of MIDI\n", (int) header->dwBufferLength); while ( index < header->dwBufferLength ) { /* New status byte? ( = new event) */ if ( midi_bytes[index] & 0x80 ) { DWORD short_msg; /* Deal with the existing event */ if ( msg[0] & 0x80 ) { short_msg = PACK_MIDI(msg[0], msg[1], msg[2]); DPRINT("Complete msg is 0x%x %d %d\n", (int) msg[0], (int) msg[1], (int) msg[2]); ProcessShortMidiMessage(device_info, short_msg); } /* Set new running status and start recording the event */ DPRINT("Set new running status\n"); device_info->running_status = midi_bytes[index]; msg[0] = midi_bytes[index]; msg_index = 1; } /* Unexpected data byte? ( = re-use previous status) */ else if ( msg_index == 0 ) { if ( device_info->running_status & 0x80 ) { DPRINT("Retrieving running status\n"); msg[0] = device_info->running_status; msg[1] = midi_bytes[index]; msg_index = 2; } else DPRINT("garbage\n"); } /* Expected data ( = append to message until buffer full) */ else { DPRINT("Next byte...\n"); msg[msg_index] = midi_bytes[index]; msg_index ++; if ( msg_index > 2 ) { DWORD short_msg; short_msg = PACK_MIDI(msg[0], msg[1], msg[2]); DPRINT("Complete msg is 0x%x %d %d\n", (int) msg[0], (int) msg[1], (int) msg[2]); ProcessShortMidiMessage(device_info, short_msg); /* Reinit */ msg_index = 0; msg[0] = msg[1] = msg[2] = 0; } } index ++; } /* We're meant to clear MHDR_DONE and set MHDR_INQUEUE but since we deal with everything here and now we might as well just say so. */ header->dwFlags |= MHDR_DONE; header->dwFlags &= ~ MHDR_INQUEUE; DPRINT("Success? %d\n", CallClient(the_device, MOM_DONE, (DWORD_PTR) header, 0)); return MMSYSERR_NOERROR; }
/*----------------------------------------------------------------------- Restore the state of a pv_peer_t from disk and add it to the pv_t. -----------------------------------------------------------------------*/ static dp_result_t pv_peer_thaw(pv_t *pv, FILE *fp) { pv_peer_t *peer; int i; short dirty; unsigned long n_vars; long sig; dpid_t id; dp_result_t err; /* Header */ if ((fread(&sig, sizeof(sig), 1, fp) != 1) || (fread(&dirty, sizeof(dirty), 1, fp) != 1) || (fread(&id, sizeof(id), 1, fp) != 1) || (fread(&n_vars, sizeof(n_vars), 1, fp) != 1)) { DPRINT(("pv_peer_thaw: can't read header\n")); return dp_RES_EMPTY; } if (sig != 0x12340009) { DPRINT(("pv_peer_thaw: bad sig\n")); return dp_RES_BAD; } if (n_vars > dp_PLAYERDATA_NKEYS_MAX) { DPRINT(("pv_peer_thaw: bad n_vars %d\n", n_vars)); return dp_RES_BAD; } if ((dirty != FALSE) && (dirty != TRUE)) { DPRINT(("pv_peer_thaw: bad dirty\n")); return dp_RES_BAD; } DPRINT(("pv_peer_thaw: id %d, pv %p, n_vars %d\n", id, pv, n_vars)); peer = pv_addPlayer(pv, id); if (!peer) return dp_RES_NOMEM; /* Body */ for (i=0; i < n_vars; i++) { /* Grab the variable */ pv_var_t var, *pvar; err = pv_var_thaw(&var, fp); if (err != dp_RES_OK) { DPRINT(("pv_peer_thaw: pv_var_thaw returns %d\n", err)); return err; } DPRINT(("pv_peer_thaw: peer %d, var %d, len %d\n", id, var.key, var.len)); /* Add it to the peer's var table. */ pvar = (pv_var_t *)assoctab_subscript_grow(peer->vars, var.key); if (!pvar) { DPRINT(("pv_peer_thaw: can't grow player %d's vars[%d]!\n", id, var.key)); return dp_RES_NOMEM; } /* Delete old value from heap if present */ if (pvar->buf) dp_FREE(pvar->buf); /* Copy variable at last. */ *pvar = var; } /* Ditch the incoming.buf allocated by pv_addPlayer, as pv_var_thaw * allocates its own. */ if (peer->incoming.buf) dp_FREE(peer->incoming.buf); DPRINT(("pv_peer_thaw: thawing incoming\n")); err = pv_var_thaw(&peer->incoming, fp); if (err != dp_RES_OK) return err; peer->allocated = peer->incoming.len; peer->dirty = dirty; /* No trailer */ return dp_RES_OK; }
MMRESULT FAR PASCAL modMessage( UINT device_id, UINT message, DWORD_PTR private_data, DWORD_PTR parameter1, DWORD_PTR parameter2) { switch ( message ) { case MODM_GETNUMDEVS : { /* Only one internal PC speaker device (and even that's too much) */ DPRINT("MODM_GETNUMDEVS\n"); return 1; } case MODM_GETDEVCAPS : { DPRINT("MODM_GETDEVCAPS\n"); return GetDeviceCapabilities((MIDIOUTCAPS*) parameter1); } case MODM_OPEN : { DPRINT("MODM_OPEN\n"); return OpenDevice((DeviceInfo**) private_data, (MIDIOPENDESC*) parameter1, parameter2); } case MODM_CLOSE : { DPRINT("MODM_CLOSE\n"); return CloseDevice((DeviceInfo*) private_data); } case MODM_DATA : { return ProcessShortMidiMessage((DeviceInfo*) private_data, parameter1); } case MODM_PREPARE : { /* We don't bother with this */ MIDIHDR* hdr = (MIDIHDR*) parameter1; hdr->dwFlags |= MHDR_PREPARED; return MMSYSERR_NOERROR; } case MODM_UNPREPARE : { MIDIHDR* hdr = (MIDIHDR*) parameter1; hdr->dwFlags &= ~MHDR_PREPARED; return MMSYSERR_NOERROR; } case MODM_LONGDATA : { DPRINT("LONGDATA\n"); return ProcessLongMidiMessage((DeviceInfo*) private_data, (MIDIHDR*) parameter1); } case MODM_RESET : { /* TODO */ break; } } DPRINT("Not supported %d\n", message); return MMSYSERR_NOTSUPPORTED; }
kdb_fullresync_result_t * iprop_full_resync_1( /* LINTED */ void *argp, struct svc_req *rqstp) { static kdb_fullresync_result_t ret; char tmpf[MAX_FILENAME] = {0}; char ubuf[MAX_FILENAME + sizeof (KDB5_UTIL_DUMP_STR)] = {0}; char clhost[MAXHOSTNAMELEN] = {0}; int pret, fret; kadm5_server_handle_t handle = global_server_handle; OM_uint32 min_stat; gss_name_t name = NULL; char *client_name = NULL, *service_name = NULL; char *whoami = "iprop_full_resync_1"; /* default return code */ ret.ret = UPDATE_ERROR; if (!handle) { krb5_klog_syslog(LOG_ERR, gettext("%s: server handle is NULL"), whoami); goto out; } DPRINT(("%s: start\n", whoami)); if (setup_gss_names(rqstp, &client_name, &service_name) < 0) { krb5_klog_syslog(LOG_ERR, gettext("%s: setup_gss_names failed"), whoami); goto out; } DPRINT(("%s: clprinc=`%s'\n\tsvcprinc=`%s'\n", whoami, client_name, service_name)); if (!(name = get_clnt_name(rqstp))) { krb5_klog_syslog(LOG_ERR, gettext("%s: Couldn't obtain client's name"), whoami); goto out; } if (!kadm5int_acl_check(handle->context, name, ACL_IPROP, NULL, NULL)) { ret.ret = UPDATE_PERM_DENIED; audit_kadmind_unauth(rqstp->rq_xprt, l_port, whoami, "<null>", client_name); krb5_klog_syslog(LOG_NOTICE, LOG_UNAUTH, whoami, "<null>", client_name, service_name, client_addr(rqstp, abuf)); goto out; } if (!getclhoststr(client_name, clhost, sizeof (clhost))) { krb5_klog_syslog(LOG_ERR, gettext("%s: getclhoststr failed"), whoami); goto out; } /* * construct db dump file name; kprop style name + clnt fqdn */ (void) strcpy(tmpf, "/var/krb5/slave_datatrans_"); if (strlcat(tmpf, clhost, sizeof (tmpf)) >= sizeof (tmpf)) { krb5_klog_syslog(LOG_ERR, gettext("%s: db dump file name too long; max length=%d"), whoami, (sizeof (tmpf) - 1)); goto out; } /* * note the -i; modified version of kdb5_util dump format * to include sno (serial number) */ if (strlcpy(ubuf, KDB5_UTIL_DUMP_STR, sizeof (ubuf)) >= sizeof (ubuf)) { goto out; } if (strlcat(ubuf, tmpf, sizeof (ubuf)) >= sizeof (ubuf)) { krb5_klog_syslog(LOG_ERR, gettext("%s: kdb5 util dump string too long; max length=%d"), whoami, (sizeof (ubuf) - 1)); goto out; } /* * Fork to dump the db and xfer it to the slave. * (the fork allows parent to return quickly and the child * acts like a callback to the slave). */ fret = fork(); DPRINT(("%s: fork=%d (%d)\n", whoami, fret, getpid())); switch (fret) { case -1: /* error */ if (nofork) { perror(whoami); } krb5_klog_syslog(LOG_ERR, gettext("%s: fork failed: %s"), whoami, error_message(errno)); goto out; case 0: /* child */ DPRINT(("%s: run `%s' ...\n", whoami, ubuf)); #ifdef POSIX_SIGNALS (void) sigemptyset(&s_action.sa_mask); s_action.sa_handler = SIG_DFL; (void) sigaction(SIGCHLD, &s_action, (struct sigaction *) NULL); #else (void) signal(SIGCHLD, SIG_DFL); #endif /* POSIX_SIGNALS */ /* run kdb5_util(1M) dump for IProp */ pret = pclose(popen(ubuf, "w")); DPRINT(("%s: pclose=%d\n", whoami, pret)); if (pret == -1) { if (nofork) { perror(whoami); } krb5_klog_syslog(LOG_ERR, gettext("%s: pclose(popen) failed: %s"), whoami, error_message(errno)); goto out; } DPRINT(("%s: exec `kprop -f %s %s' ...\n", whoami, tmpf, clhost)); pret = execl("/usr/lib/krb5/kprop", "kprop", "-f", tmpf, clhost, NULL); if (pret == -1) { if (nofork) { perror(whoami); } krb5_klog_syslog(LOG_ERR, gettext("%s: exec failed: %s"), whoami, error_message(errno)); goto out; } default: /* parent */ ret.ret = UPDATE_OK; /* not used by slave (sno is retrieved from kdb5_util dump) */ ret.lastentry.last_sno = 0; ret.lastentry.last_time.seconds = 0; ret.lastentry.last_time.useconds = 0; audit_kadmind_auth(rqstp->rq_xprt, l_port, whoami, "<null>", client_name, 0); krb5_klog_syslog(LOG_NOTICE, LOG_DONE, whoami, "<null>", "success", client_name, service_name, client_addr(rqstp, abuf)); goto out; } out: if (nofork) debprret(whoami, ret.ret, 0); if (client_name) free(client_name); if (service_name) free(service_name); if (name) gss_release_name(&min_stat, &name); return (&ret); }
LONG FAR PASCAL DriverProc( DWORD driver_id, HDRVR driver_handle, UINT message, LONG parameter1, LONG parameter2) { switch ( message ) { case DRV_LOAD : DPRINT("DRV_LOAD\n"); the_device = NULL; return 1L; case DRV_FREE : DPRINT("DRV_FREE\n"); return 1L; case DRV_OPEN : DPRINT("DRV_OPEN\n"); InitializeCriticalSection(&device_lock); return 1L; case DRV_CLOSE : DPRINT("DRV_CLOSE\n"); return 1L; case DRV_ENABLE : DPRINT("DRV_ENABLE\n"); return 1L; case DRV_DISABLE : DPRINT("DRV_DISABLE\n"); return 1L; /* We don't provide configuration capabilities. This used to be for things like I/O port, IRQ, DMA settings, etc. */ case DRV_QUERYCONFIGURE : DPRINT("DRV_QUERYCONFIGURE\n"); return 0L; case DRV_CONFIGURE : DPRINT("DRV_CONFIGURE\n"); return 0L; case DRV_INSTALL : DPRINT("DRV_INSTALL\n"); return DRVCNF_RESTART; }; DPRINT("???\n"); return DefDriverProc(driver_id, driver_handle, message, parameter1, parameter2); }
static NTSTATUS NTAPI MPU401DeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp) /* * FUNCTION: Handles user mode requests * ARGUMENTS: * DeviceObject = Device for request * Irp = I/O request packet describing request * RETURNS: Success or failure */ { PIO_STACK_LOCATION Stack; PDEVICE_EXTENSION DeviceExtension; ULONG ByteCount; PUCHAR Data; DPRINT("MPU401DeviceControl() called!\n"); DeviceExtension = DeviceObject->DeviceExtension; Stack = IoGetCurrentIrpStackLocation(Irp); DPRINT("Control code %d [0x%x]\n", Stack->Parameters.DeviceIoControl.IoControlCode, Stack->Parameters.DeviceIoControl.IoControlCode); switch(Stack->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_MIDI_PLAY : { DPRINT("Received IOCTL_MIDI_PLAY\n"); Data = (PUCHAR) Irp->AssociatedIrp.SystemBuffer; DPRINT("Sending %d bytes of MIDI data to 0x%d:\n", Stack->Parameters.DeviceIoControl.InputBufferLength, DeviceExtension->Port); for (ByteCount = 0; ByteCount < Stack->Parameters.DeviceIoControl.InputBufferLength; ByteCount ++) { DPRINT("0x%x ", Data[ByteCount]); MPU401_WRITE_BYTE(DeviceExtension->Port, Data[ByteCount]); // if (WaitToSend(MPU401_PORT)) // MPU401_WRITE_DATA(MPU401_PORT, Data[ByteCount]); } Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); return(STATUS_SUCCESS); } } return(STATUS_SUCCESS); /* DeviceExtension = DeviceObject->DeviceExtension; Stack = IoGetCurrentIrpStackLocation(Irp); BeepParam = (PBEEP_SET_PARAMETERS)Irp->AssociatedIrp.SystemBuffer; Irp->IoStatus.Information = 0; if (Stack->Parameters.DeviceIoControl.IoControlCode != IOCTL_BEEP_SET) { Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED; IoCompleteRequest(Irp, IO_NO_INCREMENT); return(STATUS_NOT_IMPLEMENTED); } if ((Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(BEEP_SET_PARAMETERS)) || (BeepParam->Frequency < BEEP_FREQUENCY_MINIMUM) || (BeepParam->Frequency > BEEP_FREQUENCY_MAXIMUM)) { Irp->IoStatus.Status = STATUS_INVALID_PARAMETER; IoCompleteRequest(Irp, IO_NO_INCREMENT); return(STATUS_INVALID_PARAMETER); } DueTime.QuadPart = 0; */ /* do the beep!! */ /* DPRINT("Beep:\n Freq: %lu Hz\n Dur: %lu ms\n", pbsp->Frequency, pbsp->Duration); if (BeepParam->Duration >= 0) { DueTime.QuadPart = (LONGLONG)BeepParam->Duration * -10000; KeSetTimer(&DeviceExtension->Timer, DueTime, &DeviceExtension->Dpc); HalMakeBeep(BeepParam->Frequency); DeviceExtension->BeepOn = TRUE; KeWaitForSingleObject(&DeviceExtension->Event, Executive, KernelMode, FALSE, NULL); } else if (BeepParam->Duration == (DWORD)-1) { if (DeviceExtension->BeepOn == TRUE) { HalMakeBeep(0); DeviceExtension->BeepOn = FALSE; } else { HalMakeBeep(BeepParam->Frequency); DeviceExtension->BeepOn = TRUE; } } DPRINT("Did the beep!\n"); Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); return(STATUS_SUCCESS); */ }
/********************************************************************** * SmCreateUserProcess/5 * * DESCRIPTION * * ARGUMENTS * ImagePath: absolute path of the image to run; * CommandLine: arguments and options for ImagePath; * Flags: Wait flag: Set for boot time processes and unset for * subsystems bootstrapping; * 1Mb reserve flag: Set for subsystems, unset for everything * else * Timeout: optional: used if WaitForIt==TRUE; * ProcessHandle: optional: a duplicated handle for the child process (storage provided by the caller). * * RETURN VALUE * NTSTATUS: * */ NTSTATUS NTAPI SmCreateUserProcess (LPWSTR ImagePath, LPWSTR CommandLine, ULONG Flags, PLARGE_INTEGER Timeout OPTIONAL, PRTL_USER_PROCESS_INFORMATION UserProcessInfo OPTIONAL) { UNICODE_STRING ImagePathString = { 0, 0, NULL }; UNICODE_STRING CommandLineString = { 0, 0, NULL }; UNICODE_STRING SystemDirectory = { 0, 0, NULL }; PRTL_USER_PROCESS_PARAMETERS ProcessParameters = NULL; RTL_USER_PROCESS_INFORMATION ProcessInfo = {0}; PRTL_USER_PROCESS_INFORMATION pProcessInfo = & ProcessInfo; NTSTATUS Status = STATUS_SUCCESS; DPRINT("SM: %s called\n", __FUNCTION__); if (NULL != UserProcessInfo) { pProcessInfo = UserProcessInfo; } RtlInitUnicodeString (& ImagePathString, ImagePath); RtlInitUnicodeString (& CommandLineString, CommandLine); SystemDirectory.MaximumLength = (wcslen(SharedUserData->NtSystemRoot) * sizeof(WCHAR)) + sizeof(szSystemDirectory); SystemDirectory.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, SystemDirectory.MaximumLength); if (SystemDirectory.Buffer == NULL) { Status = STATUS_NO_MEMORY; DPRINT1("SM: %s: Allocating system directory string failed (Status=0x%08lx)\n", __FUNCTION__, Status); return Status; } Status = RtlAppendUnicodeToString(& SystemDirectory, SharedUserData->NtSystemRoot); if (!NT_SUCCESS(Status)) { goto FailProcParams; } Status = RtlAppendUnicodeToString(& SystemDirectory, szSystemDirectory); if (!NT_SUCCESS(Status)) { goto FailProcParams; } Status = RtlCreateProcessParameters(& ProcessParameters, & ImagePathString, NULL, & SystemDirectory, & CommandLineString, SmSystemEnvironment, NULL, NULL, NULL, NULL); RtlFreeHeap(RtlGetProcessHeap(), 0, SystemDirectory.Buffer); if (!NT_SUCCESS(Status)) { FailProcParams: DPRINT1("SM: %s: Creating process parameters failed (Status=0x%08lx)\n", __FUNCTION__, Status); return Status; } /* Reserve lower 1Mb, if requested */ if (Flags & SM_CREATE_FLAG_RESERVE_1MB) ProcessParameters->Flags |= RTL_USER_PROCESS_PARAMETERS_RESERVE_1MB; /* Create the user process */ Status = RtlCreateUserProcess (& ImagePathString, OBJ_CASE_INSENSITIVE, ProcessParameters, NULL, NULL, NULL, FALSE, NULL, NULL, pProcessInfo); RtlDestroyProcessParameters (ProcessParameters); if (!NT_SUCCESS(Status)) { DPRINT1("SM: %s: Running \"%S\" failed (Status=0x%08lx)\n", __FUNCTION__, ImagePathString.Buffer, Status); return Status; } /* * It the caller is *not* interested in the child info, * resume it immediately. */ if (NULL == UserProcessInfo) { Status = NtResumeThread (ProcessInfo.ThreadHandle, NULL); if(!NT_SUCCESS(Status)) { DPRINT1("SM: %s: NtResumeThread failed (Status=0x%08lx)\n", __FUNCTION__, Status); } } /* Wait for process termination */ if (Flags & SM_CREATE_FLAG_WAIT) { Status = NtWaitForSingleObject (pProcessInfo->ProcessHandle, FALSE, Timeout); if (!NT_SUCCESS(Status)) { DPRINT1("SM: %s: NtWaitForSingleObject failed with Status=0x%08lx\n", __FUNCTION__, Status); } } if (NULL == UserProcessInfo) { NtClose(pProcessInfo->ProcessHandle); NtClose(pProcessInfo->ThreadHandle); } return Status; }
static VOID NTAPI MPU401Unload(PDRIVER_OBJECT DriverObject) { DPRINT("MPU401Unload() called!\n"); }
/* * @implemented */ INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData) { WORD VersionReturned = 0; DWORD ErrorCode = ERROR_SUCCESS; PWSPROCESS CurrentProcess; DPRINT("WSAStartup: %wx\n", wVersionRequested); /* Make sure that we went through DLL Init */ if (!WsDllHandle) return WSASYSNOTREADY; /* Check which version is being requested */ switch (LOBYTE(wVersionRequested)) { case 0: /* We don't support this unknown version */ ErrorCode = WSAVERNOTSUPPORTED; break; case 1: /* We support only 1.0 and 1.1 */ if (HIBYTE(wVersionRequested) == 0) { /* Caller wants 1.0, return it */ VersionReturned = wVersionRequested; } else { /* The only other version we support is 1.1 */ VersionReturned = MAKEWORD(1, 1); } break; case 2: /* We support only 2.0, 2.1 and 2.2 */ if (HIBYTE(wVersionRequested) <= 2) { /* Caller wants 2.0-2.2, return it */ VersionReturned = MAKEWORD(2, HIBYTE(wVersionRequested)); } else { /* The highest version we support is 2.2 */ VersionReturned = MAKEWORD(2, 2); } break; default: /* Return 2.2 */ VersionReturned = MAKEWORD(2, 2);; break; } /* Return the Version Requested, unless error */ lpWSAData->wVersion = VersionReturned; /* We support Winsock 2.2 */ lpWSAData->wHighVersion = MAKEWORD(2,2); lstrcpy(lpWSAData->szDescription, "WinSock 2.0"); lstrcpy(lpWSAData->szSystemStatus, "Running"); /* * On Winsock 1, the following values are returned. * Taken straight from a Winsock Test app on Windows. */ if (LOBYTE(wVersionRequested) == 1) { lpWSAData->iMaxSockets = 32767; lpWSAData->iMaxUdpDg = 65467; } else { lpWSAData->iMaxSockets = 0; lpWSAData->iMaxUdpDg = 0; } /* Enter the startup synchronization lock */ WsStartupLock(); /* Now setup all our objects */ while (TRUE) { /* Make sure we don't already have a process */ CurrentProcess = WsGetProcess(); if (CurrentProcess) break; /* Setup the process object support */ ErrorCode = WsProcStartup(); if (ErrorCode != ERROR_SUCCESS) break; /* Setup the process object support */ ErrorCode = WsSockStartup(); if (ErrorCode != ERROR_SUCCESS) break; /* Setup the process object support */ ErrorCode = WsThreadStartup(); if (ErrorCode != ERROR_SUCCESS) break; /* Try getting the process now */ CurrentProcess = WsGetProcess(); if (!CurrentProcess) { /* Something is weird... */ ErrorCode = WSASYSNOTREADY; break; } } /* Check if all worked */ if (ErrorCode == ERROR_SUCCESS) { /* Set the requested version */ WsProcSetVersion(CurrentProcess, wVersionRequested); /* Increase the reference count */ InterlockedIncrement(&CurrentProcess->RefCount); } /* Leave the startup lock */ WsStartupUnlock(); /* Return any Error */ return ErrorCode; }
/// <summary> /// Initialize dynamic data. /// </summary> /// <param name="pData">Data to initialize</param> /// <returns>Status code</returns> NTSTATUS BBInitDynamicData( IN OUT PDYNAMIC_DATA pData ) { NTSTATUS status = STATUS_SUCCESS; RTL_OSVERSIONINFOEXW verInfo = { 0 }; ULONG buildNo = 0; if (pData == NULL) return STATUS_INVALID_ADDRESS; RtlZeroMemory( pData, sizeof( DYNAMIC_DATA ) ); verInfo.dwOSVersionInfoSize = sizeof( verInfo ); status = RtlGetVersion( (PRTL_OSVERSIONINFOW)&verInfo ); if (status == STATUS_SUCCESS) { ULONG ver_short = (verInfo.dwMajorVersion << 8) | (verInfo.dwMinorVersion << 4) | verInfo.wServicePackMajor; pData->ver = (WinVer)ver_short; // Get kernel build number status = BBGetBuildNO( &buildNo ); // Validate current driver version pData->correctBuild = TRUE; #if defined(_WIN7_) if (ver_short != WINVER_7 && ver_short != WINVER_7_SP1) return STATUS_NOT_SUPPORTED; if(ver_short == WINVER_7_SP1 && buildNo != 18798) pData->correctBuild = FALSE; #elif defined(_WIN8_) if (ver_short != WINVER_8) return STATUS_NOT_SUPPORTED; #elif defined (_WIN81_) if (ver_short != WINVER_81) return STATUS_NOT_SUPPORTED; if (buildNo != 17328) pData->correctBuild = FALSE; #elif defined (_WIN10_) if (ver_short != WINVER_10) return STATUS_NOT_SUPPORTED; if (verInfo.dwBuildNumber != 9926) pData->correctBuild = FALSE; #endif DPRINT( "BlackBone: OS version %d.%d.%d.%d.%d.%d - 0x%x\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion, verInfo.dwBuildNumber, verInfo.wServicePackMajor, verInfo.wServicePackMinor, buildNo, ver_short ); switch (ver_short) { // Windows 7 // Windows 7 SP1, build 18798 case WINVER_7: case WINVER_7_SP1: pData->KExecOpt = 0x0D2; pData->Protection = 0x43C; // Bitfield, bit index - 0xB pData->ObjTable = 0x200; pData->VadRoot = 0x448; pData->NtProtectIndex = 0x04D; pData->NtCreateThdIndex = 0x0A5; pData->NtTermThdIndex = 0x50; pData->PrevMode = 0x1F6; pData->ExitStatus = 0x380; pData->MiAllocPage = (ver_short == WINVER_7_SP1) ? 0 : 0; pData->ExRemoveTable = (ver_short == WINVER_7_SP1) ? 0x32A870 : 0x32D404; break; // Windows 8 case WINVER_8: pData->KExecOpt = 0x1B7; pData->Protection = 0x648; pData->ObjTable = 0x408; pData->VadRoot = 0x590; pData->NtProtectIndex = 0x04E; pData->NtCreateThdIndex = 0x0AF; pData->NtTermThdIndex = 0x51; pData->PrevMode = 0x232; pData->ExitStatus = 0x450; pData->MiAllocPage = 0x3AF374; pData->ExRemoveTable = 0x487518; break; // Windows 8.1, build 17328 case WINVER_81: pData->KExecOpt = 0x1B7; pData->Protection = 0x67A; pData->ObjTable = 0x408; pData->VadRoot = 0x5D8; pData->NtCreateThdIndex = 0xB0; pData->NtTermThdIndex = 0x52; pData->PrevMode = 0x232; pData->ExitStatus = 0x6D8; pData->MiAllocPage = 0; pData->ExRemoveTable = 0x432A88; // 0x38E320; break; // Windows 10, technical preview, build 9926 case WINVER_10: pData->KExecOpt = 0x1BF; pData->Protection = 0x69A; pData->ObjTable = 0x418; pData->VadRoot = 0x5F8; pData->NtCreateThdIndex = 0xB2; pData->NtTermThdIndex = 0x53; pData->PrevMode = 0x232; pData->ExitStatus = 0x6E0; pData->MiAllocPage = 0; pData->ExRemoveTable = 0x4645B0; break; default: break; } return (pData->VadRoot != 0 ? status : STATUS_INVALID_KERNEL_INFO_VERSION); } return status; }
static NTSTATUS IopGetRelatedDevice(PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData) { UNICODE_STRING RootDeviceName; PDEVICE_OBJECT DeviceObject = NULL; PDEVICE_NODE DeviceNode = NULL; PDEVICE_NODE RelatedDeviceNode; UNICODE_STRING TargetDeviceInstance; NTSTATUS Status = STATUS_SUCCESS; ULONG Relation = 0; ULONG MaximumLength = 0; DPRINT("IopGetRelatedDevice() called\n"); DPRINT("Device name: %wZ\n", &RelatedDeviceData->TargetDeviceInstance); Status = IopCaptureUnicodeString(&TargetDeviceInstance, &RelatedDeviceData->TargetDeviceInstance); if (!NT_SUCCESS(Status)) { return Status; } _SEH2_TRY { Relation = RelatedDeviceData->Relation; MaximumLength = RelatedDeviceData->RelatedDeviceInstanceLength; ProbeForWrite(RelatedDeviceData->RelatedDeviceInstance, MaximumLength, sizeof(WCHAR)); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { if (TargetDeviceInstance.Buffer != NULL) { ExFreePool(TargetDeviceInstance.Buffer); } _SEH2_YIELD(return _SEH2_GetExceptionCode()); } _SEH2_END; RtlInitUnicodeString(&RootDeviceName, L"HTREE\\ROOT\\0"); if (RtlEqualUnicodeString(&TargetDeviceInstance, &RootDeviceName, TRUE)) { DeviceNode = IopRootDeviceNode; if (TargetDeviceInstance.Buffer != NULL) { ExFreePool(TargetDeviceInstance.Buffer); } } else { /* Get the device object */ DeviceObject = IopGetDeviceObjectFromDeviceInstance(&TargetDeviceInstance); if (TargetDeviceInstance.Buffer != NULL) { ExFreePool(TargetDeviceInstance.Buffer); } if (DeviceObject == NULL) return STATUS_NO_SUCH_DEVICE; DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode; } switch (Relation) { case PNP_GET_PARENT_DEVICE: RelatedDeviceNode = DeviceNode->Parent; break; case PNP_GET_CHILD_DEVICE: RelatedDeviceNode = DeviceNode->Child; break; case PNP_GET_SIBLING_DEVICE: RelatedDeviceNode = DeviceNode->Sibling; break; default: if (DeviceObject != NULL) { ObDereferenceObject(DeviceObject); } return STATUS_INVALID_PARAMETER; } if (RelatedDeviceNode == NULL) { if (DeviceObject) { ObDereferenceObject(DeviceObject); } return STATUS_NO_SUCH_DEVICE; } if (RelatedDeviceNode->InstancePath.Length > MaximumLength) { if (DeviceObject) { ObDereferenceObject(DeviceObject); } return STATUS_BUFFER_TOO_SMALL; } /* Copy related device instance name */ _SEH2_TRY { RtlCopyMemory(RelatedDeviceData->RelatedDeviceInstance, RelatedDeviceNode->InstancePath.Buffer, RelatedDeviceNode->InstancePath.Length); RelatedDeviceData->RelatedDeviceInstanceLength = RelatedDeviceNode->InstancePath.Length; } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { Status = _SEH2_GetExceptionCode(); } _SEH2_END; if (DeviceObject != NULL) { ObDereferenceObject(DeviceObject); } DPRINT("IopGetRelatedDevice() done\n"); return Status; }