1/*
2 * Copyright (c) 2007 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23// public
24#include <IOKit/firewire/IOFireWireController.h>
25#include <IOKit/firewire/IOFWPHYPacketListener.h>
26
27#include "FWDebugging.h"
28
29OSDefineMetaClassAndStructors( IOFWPHYPacketListener, OSObject )
30
31OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 0 );
32OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 1 );
33OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 2 );
34OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 3 );
35OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 4 );
36OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 5 );
37OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 6 );
38OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 7 );
39OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 8 );
40OSMetaClassDefineReservedUnused( IOFWPHYPacketListener, 9 );
41
42// createWithController
43//
44//
45
46IOFWPHYPacketListener * IOFWPHYPacketListener::createWithController( IOFireWireController * controller )
47{
48    IOReturn				status = kIOReturnSuccess;
49    IOFWPHYPacketListener * me;
50
51    if( status == kIOReturnSuccess )
52    {
53        me = OSTypeAlloc( IOFWPHYPacketListener );
54        if( me == NULL )
55            status = kIOReturnNoMemory;
56    }
57
58    if( status == kIOReturnSuccess )
59    {
60        bool success = me->initWithController( controller );
61		if( !success )
62		{
63			status = kIOReturnError;
64		}
65    }
66
67    if( status != kIOReturnSuccess )
68    {
69        me = NULL;
70    }
71
72	FWKLOG(( "IOFWPHYPacketListener::create() - created new IOFWPHYPacketListener %p\n", me ));
73
74    return me;
75}
76
77// initWithController
78//
79//
80
81bool IOFWPHYPacketListener::initWithController( IOFireWireController * control )
82{
83	bool success = OSObject::init();
84	FWPANICASSERT( success == true );
85
86	fControl = control;
87
88	FWKLOG(( "IOFWPHYPacketListener::initWithController() - IOFWPHYPacketListener %p initialized\n", this  ));
89
90	return true;
91}
92
93// free
94//
95//
96
97void IOFWPHYPacketListener::free()
98{
99	FWKLOG(( "IOFWPHYPacketListener::free() - freeing IOFWPHYPacketListener %p\n", this ));
100
101	OSObject::free();
102}
103
104///////////////////////////////////////////////////////////////////////////////////////
105#pragma mark -
106
107// activate
108//
109//
110
111IOReturn IOFWPHYPacketListener::activate( void )
112{
113    return fControl->activatePHYPacketListener( this );
114}
115
116// deactivate
117//
118//
119
120void IOFWPHYPacketListener::deactivate( void )
121{
122    fControl->deactivatePHYPacketListener( this );
123}
124
125// processPHYPacket
126//
127//
128
129void IOFWPHYPacketListener::processPHYPacket( UInt32 data1, UInt32 data2 )
130{
131	IOLog( "IOFWPHYPacketListener<%p>::processPHYPacket - 0x%x 0x%x\n", this, (uint32_t)data1, (uint32_t)data2 );
132
133	if( fCallback )
134	{
135		(fCallback)( fRefCon, data1, data2 );
136	}
137}
138
139// setCallback
140//
141//
142
143void IOFWPHYPacketListener::setCallback( FWPHYPacketCallback callback )
144{
145	fCallback = callback;
146}
147
148// setRefCon
149//
150//
151
152void IOFWPHYPacketListener::setRefCon( void * refcon )
153{
154	fRefCon = refcon;
155}
156
157// getRefCon
158//
159//
160
161void * IOFWPHYPacketListener::getRefCon( void )
162{
163	return fRefCon;
164}
165