We explore machine learning pattern recognition techniques as a means of informing intelligent secondary user dynamic spectrum access (DSA) strategies in a cognitive radio environment. We present a framework for learning and inferring primary user protocol state at the application and MAC layers from simple energy detector features. The resulting knowledge about the primary user protocol can be exploited by a secondary user to identify access opportunities, and to recognize when secondary user traffic has disrupted the normal behavior of the primary user. We apply Bayesian nonparametric structure learning techniques to construct Hidden Markov Models (HMM) representing primary user wireless network traffic. The learned HMM models have a highly interpretable hidden state structure that provides insight into the actual state machine of the underlying communication protocol. This framework provides efficient procedures for online protocol classification and state inference that enable the secondary user to reason intelligently about the primary user environment, and develop more efficient and adaptive DSA policies. Experimental results obtained on a wireless network testbed show that our approach learns hidden states that correspond to actual primary user application layer protocol states and also detects anomalous primary user behavior caused by secondary user interference.