diff --git a/BthPS3/Connection.c b/BthPS3/Connection.c index db50d0f..fb148ff 100644 --- a/BthPS3/Connection.c +++ b/BthPS3/Connection.c @@ -119,8 +119,20 @@ ClientConnections_CreateAndInsert( WDF_OBJECT_ATTRIBUTES_INIT(&attributes); attributes.ParentObject = connectionObject; - ExInitializeFastMutex(&connectionCtx->HidControlChannel.ConnectionStateLock); - + status = WdfSpinLockCreate( + &attributes, + &connectionCtx->HidControlChannel.ConnectionStateLock + ); + if (!NT_SUCCESS(status)) { + TraceEvents(TRACE_LEVEL_ERROR, + TRACE_CONNECTION, + "WdfSpinLockCreate for HidControlChannel failed with status %!STATUS!", + status + ); + + goto exitFailure; + } + connectionCtx->HidControlChannel.ConnectionState = ConnectionStateInitialized; // @@ -153,8 +165,20 @@ ClientConnections_CreateAndInsert( WDF_OBJECT_ATTRIBUTES_INIT(&attributes); attributes.ParentObject = connectionObject; - ExInitializeFastMutex(&connectionCtx->HidInterruptChannel.ConnectionStateLock); - + status = WdfSpinLockCreate( + &attributes, + &connectionCtx->HidInterruptChannel.ConnectionStateLock + ); + if (!NT_SUCCESS(status)) { + TraceEvents(TRACE_LEVEL_ERROR, + TRACE_CONNECTION, + "WdfSpinLockCreate for HidInterruptChannel failed with status %!STATUS!", + status + ); + + goto exitFailure; + } + connectionCtx->HidInterruptChannel.ConnectionState = ConnectionStateInitialized; // diff --git a/BthPS3/Connection.h b/BthPS3/Connection.h index 5dd5382..56c13f5 100644 --- a/BthPS3/Connection.h +++ b/BthPS3/Connection.h @@ -62,7 +62,7 @@ typedef struct _BTHPS3_CLIENT_L2CAP_CHANNEL { BTHPS3_CONNECTION_STATE ConnectionState; - FAST_MUTEX ConnectionStateLock; + WDFSPINLOCK ConnectionStateLock; L2CAP_CHANNEL_HANDLE ChannelHandle; diff --git a/BthPS3/L2CAP.c b/BthPS3/L2CAP.c index 5a1fbf9..b38c568 100644 --- a/BthPS3/L2CAP.c +++ b/BthPS3/L2CAP.c @@ -425,16 +425,16 @@ L2CAP_PS3_ControlConnectResponseCompleted( // if (NT_SUCCESS(status)) { - ExAcquireFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock); - { - clientConnection->HidControlChannel.ConnectionState = ConnectionStateConnected; + WdfSpinLockAcquire(clientConnection->HidControlChannel.ConnectionStateLock); - // - // This will be set again once disconnect has occurred - // - //KeClearEvent(&clientConnection->HidControlChannel.DisconnectEvent); - } - ExReleaseFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock); + clientConnection->HidControlChannel.ConnectionState = ConnectionStateConnected; + + // + // This will be set again once disconnect has occurred + // + //KeClearEvent(&clientConnection->HidControlChannel.DisconnectEvent); + + WdfSpinLockRelease(clientConnection->HidControlChannel.ConnectionStateLock); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_L2CAP, @@ -492,16 +492,16 @@ L2CAP_PS3_InterruptConnectResponseCompleted( // if (NT_SUCCESS(status)) { - ExAcquireFastMutex(&clientConnection->HidInterruptChannel.ConnectionStateLock); - { - clientConnection->HidInterruptChannel.ConnectionState = ConnectionStateConnected; + WdfSpinLockAcquire(clientConnection->HidInterruptChannel.ConnectionStateLock); + + clientConnection->HidInterruptChannel.ConnectionState = ConnectionStateConnected; + + // + // This will be set again once disconnect has occurred + // + //KeClearEvent(&clientConnection->HidInterruptChannel.DisconnectEvent); - // - // This will be set again once disconnect has occurred - // - //KeClearEvent(&clientConnection->HidInterruptChannel.DisconnectEvent); - } - ExReleaseFastMutex(&clientConnection->HidInterruptChannel.ConnectionStateLock); + WdfSpinLockRelease(clientConnection->HidInterruptChannel.ConnectionStateLock); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_L2CAP, @@ -511,9 +511,9 @@ L2CAP_PS3_InterruptConnectResponseCompleted( // // Control channel is expected to be established by now // - ExAcquireFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock); + WdfSpinLockAcquire(clientConnection->HidControlChannel.ConnectionStateLock); controlState = clientConnection->HidInterruptChannel.ConnectionState; - ExReleaseFastMutex(&clientConnection->HidControlChannel.ConnectionStateLock); + WdfSpinLockRelease(clientConnection->HidControlChannel.ConnectionStateLock); if (controlState != ConnectionStateConnected) { @@ -948,7 +948,7 @@ L2CAP_PS3_RemoteDisconnect( { struct _BRB_L2CA_CLOSE_CHANNEL* disconnectBrb = NULL; - ExAcquireFastMutex(&Channel->ConnectionStateLock); + WdfSpinLockAcquire(Channel->ConnectionStateLock); if (Channel->ConnectionState == ConnectionStateConnecting) { @@ -967,7 +967,7 @@ L2CAP_PS3_RemoteDisconnect( // KeClearEvent(&Channel->DisconnectEvent); - ExReleaseFastMutex(&Channel->ConnectionStateLock); + WdfSpinLockRelease(Channel->ConnectionStateLock); return TRUE; } @@ -977,12 +977,12 @@ L2CAP_PS3_RemoteDisconnect( // Do nothing if we are not connected // - ExReleaseFastMutex(&Channel->ConnectionStateLock); + WdfSpinLockRelease(Channel->ConnectionStateLock); return FALSE; } Channel->ConnectionState = ConnectionStateDisconnecting; - ExReleaseFastMutex(&Channel->ConnectionStateLock); + WdfSpinLockRelease(Channel->ConnectionStateLock); // // We are now sending the disconnect, so clear the event. @@ -1036,9 +1036,9 @@ L2CAP_PS3_ChannelDisconnectCompleted( TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_L2CAP, "%!FUNC! Entry (%!STATUS!)", Params->IoStatus.Status); - ExAcquireFastMutex(&channel->ConnectionStateLock); + WdfSpinLockAcquire(channel->ConnectionStateLock); channel->ConnectionState = ConnectionStateDisconnected; - ExReleaseFastMutex(&channel->ConnectionStateLock); + WdfSpinLockRelease(channel->ConnectionStateLock); // // Disconnect complete, set the event