Permalink
Browse files

move to using unicode strings and integrate server name lookup and IP…

…v6 support
  • Loading branch information...
1 parent 09ea538 commit 5d76cfb2d7cbf3b9bd594c1e3dc8bab36df695ce @02strich committed Mar 21, 2012
Showing with 88 additions and 33 deletions.
  1. +1 −1 driver/minstream.cpp
  2. +2 −2 driver/minwave.cpp
  3. +1 −1 driver/minwave.h
  4. +1 −1 driver/prvprop.h
  5. +75 −23 driver/savedata.cpp
  6. +5 −2 driver/savedata.h
  7. +3 −3 proppage/audionet_prop.cpp
@@ -139,7 +139,7 @@ Return Value:
if (!m_fCapture) {
ntStatus = m_SaveData.SetDataFormat(DataFormat_);
if (NT_SUCCESS(ntStatus)) {
- ntStatus = m_SaveData.Initialize();
+ ntStatus = m_SaveData.Initialize(m_pMiniport->m_cServerName);
}
}
}
View
@@ -670,7 +670,7 @@ Return Value:
return ntStatus;
// copy value
- RtlCopyMemory(pAudioNetServer->name, m_ServerName, 255);
+ RtlCopyMemory(pAudioNetServer->name, m_cServerName, sizeof(m_cServerName));
ntStatus = STATUS_SUCCESS;
} else if (PropertyRequest->Verb & KSPROPERTY_TYPE_SET) {
@@ -688,7 +688,7 @@ Return Value:
return ntStatus;
// copy value
- RtlCopyMemory(m_ServerName, pAudioNetServer->name, 255);
+ RtlCopyMemory(m_cServerName, pAudioNetServer->name, sizeof(m_cServerName));
// we seem to be successful
ntStatus = STATUS_SUCCESS;
View
@@ -59,7 +59,7 @@ class CMiniportWaveCyclic : public IMiniportWaveCyclic, public CUnknown {
ULONG m_MaxSampleRatePcm;
// Settings for new streams
- char m_ServerName[255];
+ wchar_t m_cServerName[255];
protected:
NTSTATUS ValidateFormat(IN PKSDATAFORMAT pDataFormat);
View
@@ -29,7 +29,7 @@ const int KSPROPERTY_STREAMING_ENDPOINT = 1;
// Types
//=============================================================================
typedef struct {
- char name[255];
+ wchar_t name[255];
} AudioNetServer;
typedef AudioNetServer *PAudioNetServer;
View
@@ -197,12 +197,15 @@ PSAVEWORKER_PARAM CSaveData::GetNewWorkItem(void) {
#pragma code_seg("PAGE")
//=============================================================================
-NTSTATUS CSaveData::Initialize(void) {
+NTSTATUS CSaveData::Initialize(const wchar_t* cServerName) {
PAGED_CODE();
NTSTATUS ntStatus = STATUS_SUCCESS;
DPF_ENTER(("[CSaveData::Initialize]"));
+
+ // copy over servername
+ RtlCopyMemory(m_cServerName, cServerName, sizeof(m_cServerName));
// Allocate memory for data buffer.
if (NT_SUCCESS(ntStatus)) {
@@ -301,23 +304,84 @@ VOID SaveFrameWorkerCallback(PDEVICE_OBJECT pDeviceObject, IN PVOID Context) {
#pragma code_seg()
//=============================================================================
-void CSaveData::CreateSocket(PSOCKADDR localAddress) {
+void CSaveData::CreateSocket(void) {
NTSTATUS status;
WSK_PROVIDER_NPI pronpi;
+ PSOCKADDR locaddr;
+ SOCKADDR_IN locaddr4 = { AF_INET, RtlUshortByteSwap(4009), 0, 0};
+ SOCKADDR_IN6 locaddr6 = { AF_INET6, RtlUshortByteSwap(4009), 0, IN6ADDR_ANY_INIT, 0};
+
+ // server name lookup
+ UNICODE_STRING uniNodeName;
+ PADDRINFOEXW results;
+ DPF_ENTER(("[CSaveData::CreateSocket] server name: %ws", m_cServerName));
+
// capture WSK provider
status = WskCaptureProviderNPI(&m_wskSampleRegistration, WSK_INFINITE_WAIT, &pronpi);
if(!NT_SUCCESS(status)){
DPF(D_TERSE, ("Failed to capture provider NPI: 0x%X\n", status));
return;
}
+ // convert server name to UNICODE_STRING
+ RtlInitUnicodeString(&uniNodeName, m_cServerName);
+
+ // resolve configured server name
+ IoReuseIrp(m_irp, STATUS_UNSUCCESSFUL);
+ IoSetCompletionRoutine(m_irp, WskSampleSyncIrpCompletionRoutine, &m_syncEvent, TRUE, TRUE, TRUE);
+ pronpi.Dispatch->WskGetAddressInfo (
+ pronpi.Client,
+ &uniNodeName,
+ NULL,
+ NS_ALL,
+ NULL, // Provider
+ NULL,
+ &results,
+ NULL, // OwningProcess
+ NULL, // OwningThread
+ m_irp);
+ KeWaitForSingleObject(&m_syncEvent, Executive, KernelMode, FALSE, NULL);
+
+ DPF(D_TERSE, ("WskGetAddressInfo: %x", m_irp->IoStatus.Status));
+ if (!NT_SUCCESS(m_irp->IoStatus.Status)) {
+ DPF(D_TERSE, ("WskGetAddressInfo failed: %x.", m_irp->IoStatus.Status));
+
+ // release the provider again, as we are finished with it
+ WskReleaseProviderNPI(&m_wskSampleRegistration);
+
+ return;
+ } else if (results->ai_family == AF_INET) {
+ // copy remote address and set port
+ RtlCopyMemory(&m_sServerAddr, results->ai_addr, sizeof(SOCKADDR_IN));
+ ((PSOCKADDR_IN)&m_sServerAddr)->sin_port = RtlUshortByteSwap(4010);
+
+ // create IPv4 socket
+ locaddr = (PSOCKADDR) &locaddr4;
+ } else if (results->ai_family == AF_INET6) {
+ RtlCopyMemory(&m_sServerAddr, results->ai_addr, sizeof(SOCKADDR_IN6));
+ ((PSOCKADDR_IN6)&m_sServerAddr)->sin6_port = RtlUshortByteSwap(4010);
+
+ // create IPv6 socket
+ locaddr = (PSOCKADDR) &locaddr6;
+ } else {
+ DPF(D_TERSE, ("WskGetAddressInfo did not find IPv4 or IPv6 address."));
+
+ // release the provider again, as we are finished with it
+ WskReleaseProviderNPI(&m_wskSampleRegistration);
+
+ return;
+ }
+ pronpi.Dispatch->WskFreeAddressInfo(pronpi.Client, results);
+
+ DPF(D_TERSE, ("ss_family: %x", m_sServerAddr.ss_family));
+
// create socket
IoReuseIrp(m_irp, STATUS_UNSUCCESSFUL);
IoSetCompletionRoutine(m_irp, WskSampleSyncIrpCompletionRoutine, &m_syncEvent, TRUE, TRUE, TRUE);
pronpi.Dispatch->WskSocket(
pronpi.Client,
- AF_INET,
+ m_sServerAddr.ss_family,
SOCK_DGRAM,
IPPROTO_UDP,
WSK_FLAG_DATAGRAM_SOCKET,
@@ -340,6 +404,10 @@ void CSaveData::CreateSocket(PSOCKADDR localAddress) {
((PWSK_PROVIDER_BASIC_DISPATCH)m_socket->Dispatch)->WskCloseSocket(m_socket, m_irp);
KeWaitForSingleObject(&m_syncEvent, Executive, KernelMode, FALSE, NULL);
}
+
+ // release the provider again, as we are finished with it
+ WskReleaseProviderNPI(&m_wskSampleRegistration);
+
return;
}
@@ -351,8 +419,8 @@ void CSaveData::CreateSocket(PSOCKADDR localAddress) {
// bind the socket
IoReuseIrp(m_irp, STATUS_UNSUCCESSFUL);
- IoSetCompletionRoutine(m_irp, WskSampleSyncIrpCompletionRoutine, &m_syncEvent, TRUE, TRUE, TRUE);
- status = ((PWSK_PROVIDER_CONNECTION_DISPATCH)(m_socket->Dispatch))->WskBind(m_socket, localAddress, 0, m_irp);
+ IoSetCompletionRoutine(m_irp, WskSampleSyncIrpCompletionRoutine, &m_syncEvent, TRUE, TRUE, TRUE);
+ status = ((PWSK_PROVIDER_DATAGRAM_DISPATCH)(m_socket->Dispatch))->WskBind(m_socket, locaddr, 0, m_irp);
KeWaitForSingleObject(&m_syncEvent, Executive, KernelMode, FALSE, NULL);
DPF(D_TERSE, ("WskBind: %x", m_irp->IoStatus.Status));
@@ -373,28 +441,12 @@ void CSaveData::CreateSocket(PSOCKADDR localAddress) {
//=============================================================================
void CSaveData::SendData(ULONG offset, ULONG length) {
WSK_BUF wskbuf;
- SOCKADDR_IN locaddr;
- SOCKADDR_IN remaddr;
DPF_ENTER(("[CSaveData::SendData offset=%d length=%d]", offset, length));
-
- remaddr.sin_family = AF_INET;
- remaddr.sin_port = RtlUshortByteSwap(4010);
- remaddr.sin_addr.S_un.S_un_b.s_b1 = 192;
- remaddr.sin_addr.S_un.S_un_b.s_b2 = 168;
- remaddr.sin_addr.S_un.S_un_b.s_b3 = 178;
- remaddr.sin_addr.S_un.S_un_b.s_b4 = 129;
-
- locaddr.sin_family = AF_INET;
- locaddr.sin_port = RtlUshortByteSwap(4009);
- locaddr.sin_addr.S_un.S_un_b.s_b1 = 0;
- locaddr.sin_addr.S_un.S_un_b.s_b2 = 0;
- locaddr.sin_addr.S_un.S_un_b.s_b3 = 0;
- locaddr.sin_addr.S_un.S_un_b.s_b4 = 0;
// initialize transport if not done yet
if (!m_bInitialized) {
- this->CreateSocket((PSOCKADDR)&locaddr);
+ this->CreateSocket();
m_bInitialized = TRUE;
return;
@@ -407,7 +459,7 @@ void CSaveData::SendData(ULONG offset, ULONG length) {
if (m_socket) {
IoReuseIrp(m_irp, STATUS_UNSUCCESSFUL);
IoSetCompletionRoutine(m_irp, WskSampleSyncIrpCompletionRoutine, &m_syncEvent, TRUE, TRUE, TRUE);
- ((PWSK_PROVIDER_DATAGRAM_DISPATCH)(m_socket->Dispatch))->WskSendTo(m_socket, &wskbuf, 0, (PSOCKADDR)&remaddr, 0, NULL, m_irp);
+ ((PWSK_PROVIDER_DATAGRAM_DISPATCH)(m_socket->Dispatch))->WskSendTo(m_socket, &wskbuf, 0, (PSOCKADDR)&m_sServerAddr, 0, NULL, m_irp);
KeWaitForSingleObject(&m_syncEvent, Executive, KernelMode, FALSE, NULL);
DPF(D_TERSE, ("WskSendTo: %x", m_irp->IoStatus.Status));
View
@@ -86,12 +86,15 @@ class CSaveData {
BOOL m_fWriteDisabled;
BOOL m_bInitialized;
+
+ wchar_t m_cServerName[255];
+ SOCKADDR_STORAGE m_sServerAddr;
public:
CSaveData();
~CSaveData();
- NTSTATUS Initialize(void);
+ NTSTATUS Initialize(const wchar_t* cServerName);
NTSTATUS SetDataFormat(IN PKSDATAFORMAT pDataFormat);
void Disable(BOOL fDisable);
@@ -107,7 +110,7 @@ class CSaveData {
private:
static NTSTATUS InitializeWorkItems(IN PDEVICE_OBJECT DeviceObject);
- void CreateSocket(PSOCKADDR localAddress);
+ void CreateSocket(void);
void SendData(ULONG offset, ULONG length);
void SaveFrame(IN ULONG ulFrameNo, IN ULONG ulDataSize);
@@ -265,8 +265,8 @@ BOOL AudioNetPropPage_OnInitDialog(HWND ParentHwnd, HWND FocusHwnd, LPARAM lPara
// get current value
pAudioNetServer = (PAudioNetServer)((LPPROPSHEETPAGE)lParam)->lParam;
- // convert ASCII servername to unicode
- mbstowcs(wServerName, pAudioNetServer->name, 255);
+ // copy string to local buffer
+ wcsncpy(wServerName, pAudioNetServer->name, 255);
// set the server name
SetWindowText(GetDlgItem(ParentHwnd, IDC_SERVERNAME), wServerName);
@@ -310,7 +310,7 @@ BOOL AudioNetPropPage_OnApplyDialog(HWND ParentHwnd)
}
// copy value to AudioNetServer structure
- wcstombs(pAudioNetServer->name, (const wchar_t *)&wServerName, 255);
+ wcsncpy(pAudioNetServer->name, (const wchar_t *)&wServerName, 255);
// Set the AudioNet server name through the private property call.
SetAudioNetServer(gpDeviceInterfaceDetailData, pAudioNetServer);

0 comments on commit 5d76cfb

Please sign in to comment.