1/*
2 * Copyright (c) 1998-2000 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#include <CoreFoundation/CoreFoundation.h>
24
25#include "FWDebugging.h"
26#include "IOFireWireSBP2LibLogin.h"
27#include "IOFireWireSBP2LibORB.h"
28
29#include <System/libkern/OSCrossEndian.h>
30
31__BEGIN_DECLS
32#include <IOKit/iokitmig.h>
33__END_DECLS
34
35//
36// static interface table for IOFireWireSBP2LibLoginInterface
37//
38
39IOFireWireSBP2LibLoginInterface IOFireWireSBP2LibLogin::sIOFireWireSBP2LibLoginInterface =
40{
41    0,
42	&IOFireWireSBP2LibLogin::staticQueryInterface,
43	&IOFireWireSBP2LibLogin::staticAddRef,
44	&IOFireWireSBP2LibLogin::staticRelease,
45	1, 0, // version/revision
46	&IOFireWireSBP2LibLogin::staticSubmitLogin,
47	&IOFireWireSBP2LibLogin::staticSubmitLogout,
48	&IOFireWireSBP2LibLogin::staticSetLoginFlags,
49	&IOFireWireSBP2LibLogin::staticSetLoginCallback,
50	&IOFireWireSBP2LibLogin::staticSetLogoutCallback,
51	&IOFireWireSBP2LibLogin::staticSetRefCon,
52	&IOFireWireSBP2LibLogin::staticGetRefCon,
53	&IOFireWireSBP2LibLogin::staticGetMaxCommandBlockSize,
54	&IOFireWireSBP2LibLogin::staticGetLoginID,
55	&IOFireWireSBP2LibLogin::staticSetMaxPayloadSize,
56	&IOFireWireSBP2LibLogin::staticSetReconnectTime,
57	&IOFireWireSBP2LibLogin::staticCreateORB,
58	&IOFireWireSBP2LibLogin::staticSubmitORB,
59	&IOFireWireSBP2LibLogin::staticSetUnsolicitedStatusNotify,
60	&IOFireWireSBP2LibLogin::staticSetStatusNotify,
61	&IOFireWireSBP2LibLogin::staticSetFetchAgentResetCallback,
62	&IOFireWireSBP2LibLogin::staticSubmitFetchAgentReset,
63	&IOFireWireSBP2LibLogin::staticSetFetchAgentWriteCallback,
64	&IOFireWireSBP2LibLogin::staticRingDoorbell,
65	&IOFireWireSBP2LibLogin::staticEnableUnsolicitedStatus,
66	&IOFireWireSBP2LibLogin::staticSetBusyTimeoutRegisterValue,
67	&IOFireWireSBP2LibLogin::staticSetPassword
68};
69
70// alloc
71//
72// static allocator, called by factory method
73
74IUnknownVTbl ** IOFireWireSBP2LibLogin::alloc( io_connect_t connection,
75											   mach_port_t asyncPort )
76{
77    IOReturn					status = kIOReturnSuccess;
78	IOFireWireSBP2LibLogin *	me;
79	IUnknownVTbl ** 			interface = NULL;
80
81	if( status == kIOReturnSuccess )
82	{
83		me = new IOFireWireSBP2LibLogin();
84		if( me == NULL )
85			status = kIOReturnError;
86	}
87
88	if( status == kIOReturnSuccess )
89	{
90		status = me->init( connection, asyncPort );
91	}
92
93	if( status != kIOReturnSuccess )
94		delete me;
95
96	if( status == kIOReturnSuccess )
97	{
98		// we return an interface here. queryInterface will not be called. call addRef here
99		me->addRef();
100		interface = (IUnknownVTbl **) &me->fIOFireWireSBP2LibLoginInterface.pseudoVTable;
101	}
102
103	return interface;
104}
105
106// ctor
107//
108//
109
110IOFireWireSBP2LibLogin::IOFireWireSBP2LibLogin( void )
111{
112	// init cf plugin ref counting
113	fRefCount = 0;
114	fConnection = 0;
115	fLoginRef = 0;
116	fRefCon = 0;
117
118	fLoginCallbackRoutine = NULL;
119	fLoginCallbackRefCon = NULL;
120
121	fLogoutCallbackRoutine = NULL;
122	fLogoutCallbackRefCon = NULL;
123
124	fUnsolicitedStatusNotifyRoutine = NULL;
125	fUnsolicitedStatusNotifyRefCon = NULL;
126
127	fStatusNotifyRoutine = NULL;
128	fStatusNotifyRefCon = NULL;
129
130	fFetchAgentResetCallback = NULL;
131	fFetchAgentResetRefCon = NULL;
132
133	// create test driver interface map
134	fIOFireWireSBP2LibLoginInterface.pseudoVTable
135								= (IUnknownVTbl *) &sIOFireWireSBP2LibLoginInterface;
136	fIOFireWireSBP2LibLoginInterface.obj = this;
137
138}
139
140// init
141//
142//
143
144IOReturn IOFireWireSBP2LibLogin::init( io_connect_t connection, mach_port_t asyncPort )
145{
146	IOReturn status = kIOReturnSuccess;
147
148	fConnection = connection;
149	fAsyncPort = asyncPort;
150
151	FWLOG(( "IOFireWireSBP2LibLogin : fConnection %d, fAsyncPort %d\n",
152													fConnection, fAsyncPort ));
153
154	if( !fConnection || !fAsyncPort )
155		status = kIOReturnError;
156
157	if( status == kIOReturnSuccess )
158	{
159		uint32_t len = 1;
160		status = IOConnectCallScalarMethod( connection, kIOFWSBP2UserClientCreateLogin, NULL, 0, &fLoginRef, &len );
161		if( status != kIOReturnSuccess )
162			fLoginRef = 0; // just to make sure
163
164		FWLOG(( "IOFireWireSBP2LibLogin :  status = 0x%08x = fLoginRef 0x%08lx\n",
165																	status, fLoginRef ));
166	}
167
168	if( status == kIOReturnSuccess )
169	{
170		io_async_ref64_t asyncRef;
171		mach_msg_type_number_t	size = 0;
172
173		asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLogin::staticLoginCompletion;
174		asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;
175
176		status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSetLoginCallback, fAsyncPort, asyncRef, kOSAsyncRef64Count, NULL, 0, NULL, &size  );
177	}
178
179	if( status == kIOReturnSuccess )
180	{
181		io_async_ref64_t asyncRef;
182		mach_msg_type_number_t	size = 0;
183
184		asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLogin::staticLogoutCompletion;
185		asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;
186
187		status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSetLogoutCallback, fAsyncPort, asyncRef, kOSAsyncRef64Count, NULL, 0, NULL, &size  );
188	}
189
190	if( status == kIOReturnSuccess )
191	{
192		io_async_ref64_t asyncRef;
193		mach_msg_type_number_t	size = 0;
194
195		asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLogin::staticUnsolicitedStatusNotify;
196		asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;
197
198		status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSetUnsolicitedStatusNotify, fAsyncPort, asyncRef, kOSAsyncRef64Count, NULL, 0, NULL, &size  );
199	}
200
201	if( status == kIOReturnSuccess )
202	{
203		io_async_ref64_t asyncRef;
204		mach_msg_type_number_t	size = 0;
205
206		asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLogin::staticStatusNotify;
207		asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;
208
209		status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSetStatusNotify, fAsyncPort, asyncRef, kOSAsyncRef64Count, NULL, 0, NULL, &size  );
210	}
211
212	if( status == kIOReturnSuccess )
213	{
214		io_async_ref64_t asyncRef;
215		mach_msg_type_number_t	size = 0;
216
217		asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLogin::staticFetchAgentWriteCompletion;
218		asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;
219
220		status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSetFetchAgentWriteCompletion, fAsyncPort, asyncRef, kOSAsyncRef64Count, NULL, 0, NULL, &size  );
221	}
222
223	return status;
224}
225
226// dtor
227//
228//
229
230IOFireWireSBP2LibLogin::~IOFireWireSBP2LibLogin()
231{
232	if( fLoginRef )
233	{
234		IOReturn status = kIOReturnSuccess;
235
236		uint32_t len = 0;
237		status = IOConnectCallScalarMethod( fConnection,
238											kIOFWSBP2UserClientReleaseLogin,
239											&fLoginRef, 1, NULL, &len );
240		FWLOG(( "IOFireWireSBP2LibLogin : release login status = 0x%08x\n", status ));
241	}
242}
243
244
245//////////////////////////////////////////////////////////////////
246// IUnknown methods
247//
248
249// queryInterface
250//
251//
252
253HRESULT IOFireWireSBP2LibLogin::staticQueryInterface( void * self, REFIID iid, void **ppv )
254{
255	return getThis(self)->queryInterface( iid, ppv );
256}
257
258HRESULT IOFireWireSBP2LibLogin::queryInterface( REFIID iid, void **ppv )
259{
260    CFUUIDRef uuid = CFUUIDCreateFromUUIDBytes(NULL, iid);
261    HRESULT result = S_OK;
262
263	if( CFEqual(uuid, IUnknownUUID) ||  CFEqual(uuid, kIOFireWireSBP2LibLoginInterfaceID) )
264	{
265        *ppv = &fIOFireWireSBP2LibLoginInterface;
266        addRef();
267    }
268    else
269        *ppv = 0;
270
271    if( !*ppv )
272        result = E_NOINTERFACE;
273
274    CFRelease( uuid );
275
276    return result;
277}
278
279// addRef
280//
281//
282
283UInt32 IOFireWireSBP2LibLogin::staticAddRef( void * self )
284{
285	return getThis(self)->addRef();
286}
287
288UInt32 IOFireWireSBP2LibLogin::addRef()
289{
290    fRefCount += 1;
291    return fRefCount;
292}
293
294// release
295//
296//
297
298UInt32 IOFireWireSBP2LibLogin::staticRelease( void * self )
299{
300	return getThis(self)->release();
301}
302
303UInt32 IOFireWireSBP2LibLogin::release( void )
304{
305	UInt32 retVal = fRefCount;
306
307	if( 1 == fRefCount-- )
308	{
309		delete this;
310    }
311
312	return retVal;
313}
314
315//////////////////////////////////////////////////////////////////
316// IOFireWireSBP2Login methods
317
318// submitLogin
319//
320//
321
322IOReturn IOFireWireSBP2LibLogin::staticSubmitLogin( void * self )
323{
324	return getThis(self)->submitLogin();
325}
326
327IOReturn IOFireWireSBP2LibLogin::submitLogin( void )
328{
329	IOReturn status = kIOReturnSuccess;
330
331	FWLOG(( "IOFireWireSBP2LibLogin : submitLogin\n" ));
332
333	uint32_t len = 0;
334	status = IOConnectCallScalarMethod( fConnection,
335										kIOFWSBP2UserClientSubmitLogin,
336										&fLoginRef, 1, NULL, &len );
337	return status;
338}
339
340// submitLogout
341//
342//
343
344IOReturn IOFireWireSBP2LibLogin::staticSubmitLogout( void * self )
345{
346	return getThis(self)->submitLogout();
347}
348
349IOReturn IOFireWireSBP2LibLogin::submitLogout( void )
350{
351	IOReturn status = kIOReturnSuccess;
352
353	FWLOG(( "IOFireWireSBP2LibLogin : submitLogout\n" ));
354
355	uint32_t len = 0;
356	status = IOConnectCallScalarMethod( fConnection,
357										kIOFWSBP2UserClientSubmitLogout,
358										&fLoginRef, 1, NULL, &len );
359	return status;
360}
361
362// setLoginFlags
363//
364//
365
366void IOFireWireSBP2LibLogin::staticSetLoginFlags( void * self, UInt32 flags )
367{
368	getThis(self)->setLoginFlags( flags );
369}
370
371void IOFireWireSBP2LibLogin::setLoginFlags( UInt32 flags )
372{
373	FWLOG(( "IOFireWireSBP2LibLogin : setLoginFlags: 0x%08lx\n", flags ));
374
375	uint32_t len = 0;
376	uint64_t params[2];
377
378	params[0] = fLoginRef;
379	params[1] = flags;
380
381	IOConnectCallScalarMethod( fConnection,
382								kIOFWSBP2UserClientSetLoginFlags,
383								params, 2, NULL, &len );
384}
385
386// setLoginCallback
387//
388//
389
390void IOFireWireSBP2LibLogin::staticSetLoginCallback( void * self, void * refCon,
391													IOFWSBP2LoginCallback callback )
392{
393	getThis(self)->setLoginCallback( refCon, callback );
394}
395
396void IOFireWireSBP2LibLogin::setLoginCallback( void * refCon,
397													IOFWSBP2LoginCallback callback )
398{
399	fLoginCallbackRoutine = callback;
400	fLoginCallbackRefCon = refCon;
401}
402
403// setLogoutCallback
404//
405//
406
407void IOFireWireSBP2LibLogin::staticSetLogoutCallback( void * self, void * refCon,
408													IOFWSBP2LogoutCallback callback )
409{
410	getThis(self)->setLogoutCallback( refCon, callback );
411}
412
413void IOFireWireSBP2LibLogin::setLogoutCallback( void * refCon,
414													IOFWSBP2LogoutCallback callback )
415{
416	fLogoutCallbackRoutine = callback;
417	fLogoutCallbackRefCon = refCon;
418}
419
420// setRefCon
421//
422//
423
424void IOFireWireSBP2LibLogin::staticSetRefCon( void * self, void * refCon )
425{
426	getThis(self)->setRefCon( refCon );
427}
428
429void IOFireWireSBP2LibLogin::setRefCon( void * refCon )
430{
431	fRefCon = refCon;
432}
433
434// getRefCon
435//
436//
437
438void * IOFireWireSBP2LibLogin::staticGetRefCon( void * self )
439{
440	return getThis(self)->getRefCon();
441}
442
443void * IOFireWireSBP2LibLogin::getRefCon( void )
444{
445	return fRefCon;
446}
447
448// getMaxCommandBlockSize
449//
450//
451
452UInt32 IOFireWireSBP2LibLogin::staticGetMaxCommandBlockSize( void * self )
453{
454	return getThis(self)->getMaxCommandBlockSize();
455}
456
457UInt32 IOFireWireSBP2LibLogin::getMaxCommandBlockSize( void )
458{
459	IOReturn status = kIOReturnSuccess;
460	uint32_t len = 1;
461	uint64_t blockSize;
462
463	status = IOConnectCallScalarMethod( fConnection,
464									    kIOFWSBP2UserClientGetMaxCommandBlockSize,
465									    &fLoginRef, 1, &blockSize, &len );
466	if( status != kIOReturnSuccess )
467		blockSize = 0;
468
469	return (UInt32)blockSize;
470}
471
472// getLoginID
473//
474//
475
476UInt32 IOFireWireSBP2LibLogin::staticGetLoginID( void * self )
477{
478	return getThis(self)->getLoginID();
479}
480
481UInt32 IOFireWireSBP2LibLogin::getLoginID( void )
482{
483	IOReturn status = kIOReturnSuccess;
484	uint32_t len = 1;
485	uint64_t loginID;
486
487	IOConnectCallScalarMethod(	fConnection,
488								kIOFWSBP2UserClientGetLoginID,
489								&fLoginRef, 1, &loginID, &len );
490	if( status != kIOReturnSuccess )
491		loginID = 0;
492
493	return loginID;
494}
495
496// setMaxPayloadSize
497//
498//
499
500void IOFireWireSBP2LibLogin::staticSetMaxPayloadSize( void * self, UInt32 size )
501{
502	getThis(self)->setMaxPayloadSize( size );
503}
504
505void IOFireWireSBP2LibLogin::setMaxPayloadSize( UInt32 size )
506{
507	FWLOG(( "IOFireWireSBP2LibLogin : setReconnectTime = %ld\n", size ));
508
509	uint32_t len = 0;
510	uint64_t params[2];
511
512	params[0] = fLoginRef;
513	params[1] = size;
514
515	IOConnectCallScalarMethod(	fConnection,
516								kIOFWSBP2UserClientSetMaxPayloadSize,
517								params, 2, NULL, &len );
518
519}
520
521// setReconnectTime
522//
523//
524
525void IOFireWireSBP2LibLogin::staticSetReconnectTime( void * self, UInt32 time )
526{
527	getThis(self)->setReconnectTime( time );
528}
529
530void IOFireWireSBP2LibLogin::setReconnectTime( UInt32 time )
531{
532	FWLOG(( "IOFireWireSBP2LibLogin : setReconnectTime = %ld\n", time ));
533
534	uint32_t len = 0;
535	uint64_t params[2];
536
537	params[0] = fLoginRef;
538	params[1] = time;
539
540	IOConnectCallScalarMethod(	fConnection,
541								kIOFWSBP2UserClientSetReconnectTime,
542								params, 2, NULL, &len );
543
544}
545
546// createORB
547//
548//
549
550IUnknownVTbl ** IOFireWireSBP2LibLogin::staticCreateORB( void * self, REFIID iid )
551{
552	return getThis(self)->createORB(iid);
553}
554
555IUnknownVTbl ** IOFireWireSBP2LibLogin::createORB( REFIID iid )
556{
557	IOReturn status = kIOReturnSuccess;
558	IUnknownVTbl ** iunknown = NULL;
559	IUnknownVTbl ** interface = NULL;
560
561	if( !fConnection )
562		status = kIOReturnError;
563
564	if( status == kIOReturnSuccess )
565	{
566		iunknown = IOFireWireSBP2LibORB::alloc( fConnection, fAsyncPort );
567		if( iunknown == NULL )
568			status = kIOReturnNoMemory;
569	}
570
571	if( status == kIOReturnSuccess )
572	{
573		HRESULT res;
574		res = (*iunknown)->QueryInterface( iunknown, iid,
575										   (void **) &interface );
576
577		if( res != S_OK )
578			status = kIOReturnError;
579	}
580
581	if( iunknown != NULL )
582	{
583		(*iunknown)->Release(iunknown);
584	}
585
586	if( status == kIOReturnSuccess )
587		return interface;
588	else
589		return NULL;
590}
591
592// submitORB
593//
594//
595
596IOReturn IOFireWireSBP2LibLogin::staticSubmitORB( void * self, IOFireWireSBP2LibORBInterface ** orb )
597{
598	return getThis(self)->submitORB( orb );
599}
600
601IOReturn IOFireWireSBP2LibLogin::submitORB( IOFireWireSBP2LibORBInterface ** orb )
602{
603	IOReturn status = kIOReturnSuccess;
604
605	FWLOG(( "IOFireWireSBP2LibLogin : submitORB\n" ));
606
607	uint64_t ref = IOFireWireSBP2LibORB::getThis(orb)->getORBRef();
608
609	uint32_t len = 0;
610	status = IOConnectCallScalarMethod( fConnection,
611										kIOFWSBP2UserClientSubmitORB,
612										&ref, 1, NULL, &len );
613	return status;
614}
615
616// setUnsolicitedStatusNotify
617//
618//
619
620void IOFireWireSBP2LibLogin::staticSetUnsolicitedStatusNotify( void * self, void * refCon,
621														IOFWSBP2NotifyCallback callback )
622{
623	getThis(self)->setUnsolicitedStatusNotify( refCon, callback );
624}
625
626void IOFireWireSBP2LibLogin::setUnsolicitedStatusNotify( void * refCon, 																		 IOFWSBP2NotifyCallback callback )
627{
628	fUnsolicitedStatusNotifyRoutine = callback;
629	fUnsolicitedStatusNotifyRefCon = refCon;
630}
631
632// setStatusNotify
633//
634//
635
636void IOFireWireSBP2LibLogin::staticSetStatusNotify( void * self, void * refCon,
637														IOFWSBP2NotifyCallback callback )
638{
639	getThis(self)->setStatusNotify( refCon, callback );
640}
641
642void IOFireWireSBP2LibLogin::setStatusNotify( void * refCon,
643													IOFWSBP2NotifyCallback callback )
644{
645	fStatusNotifyRoutine = callback;
646	fStatusNotifyRefCon = refCon;
647}
648
649//////////////////////////////////////////////////////////////////
650// callback methods
651
652// loginCompletion
653//
654//
655
656void IOFireWireSBP2LibLogin::staticLoginCompletion( void *refcon, IOReturn result,
657													io_user_reference_t *args, int numArgs )
658{
659	((IOFireWireSBP2LibLogin*)refcon)->loginCompletion( result, args, numArgs );
660}
661
662void IOFireWireSBP2LibLogin::loginCompletion( IOReturn result, io_user_reference_t *args, int numArgs )
663{
664	FWLOG(( "IOFireWireSBP2LibLogin : loginCompletion numArgs = %d\n",  numArgs));
665
666	FWSBP2LoginCompleteParams params;
667
668	UInt32 loginResponse[2];
669
670	{
671		int i;
672
673		for( i = 0; i < 2; i++ )
674		{
675			IF_ROSETTA()
676			{
677				loginResponse[i] = OSSwapInt32( (UInt32)args[2+i] );
678			}
679			else
680			{
681				loginResponse[i] = (UInt32)args[2+i];
682			}
683		}
684	}
685
686	UInt32 statusBlock[4];
687
688	{
689		int i;
690
691		for( i = 0; i < 4; i++ )
692		{
693			IF_ROSETTA()
694			{
695				statusBlock[i] = OSSwapInt32( (UInt32)args[7+i] );
696			}
697			else
698			{
699				statusBlock[i] = (UInt32)args[7+i];
700			}
701		}
702	}
703
704	params.refCon = (void*)fRefCon;
705	params.generation = (UInt32)args[0];
706	params.status = (IOReturn)args[1];
707	params.loginResponse = (FWSBP2LoginResponse*)&loginResponse;
708	params.statusBlock = (FWSBP2StatusBlock*)&statusBlock;
709	params.statusBlockLength = (UInt32)args[6];
710
711	if( fLoginCallbackRoutine != NULL )
712		(fLoginCallbackRoutine)( fLoginCallbackRefCon, &params );
713}
714
715// logoutCompletion
716//
717//
718
719void IOFireWireSBP2LibLogin::staticLogoutCompletion( void *refcon, IOReturn result,
720													io_user_reference_t *args, int numArgs )
721{
722	((IOFireWireSBP2LibLogin*)refcon)->logoutCompletion( result, args, numArgs );
723}
724
725void IOFireWireSBP2LibLogin::logoutCompletion( IOReturn result, io_user_reference_t *args, int numArgs )
726{
727	FWLOG(( "IOFireWireSBP2LibLogin : logoutCompletion numArgs = %d\n", numArgs ));
728
729	FWSBP2LogoutCompleteParams params;
730
731	UInt32 statusBlock[4];
732	{
733		int i;
734
735		for( i = 0; i < 4; i++ )
736		{
737			IF_ROSETTA()
738			{
739				statusBlock[i] = OSSwapInt32( (UInt32)args[3+i] );
740			}
741			else
742			{
743				statusBlock[i] = (UInt32)args[3+i];
744			}
745		}
746	}
747
748	params.refCon = (void*)fRefCon;
749	params.generation = (UInt32)args[0];
750	params.status = (IOReturn)args[1];
751	params.statusBlock = (FWSBP2StatusBlock*)&statusBlock;
752	params.statusBlockLength = (UInt32)args[2];
753
754	if( fLogoutCallbackRoutine != NULL )
755		(fLogoutCallbackRoutine)( fLogoutCallbackRefCon, &params );
756}
757
758// unsolicitedNotify
759//
760//
761
762void IOFireWireSBP2LibLogin::staticUnsolicitedStatusNotify( void *refcon, IOReturn result,
763													io_user_reference_t *args, int numArgs )
764{
765	((IOFireWireSBP2LibLogin*)refcon)->unsolicitedStatusNotify( result, args, numArgs );
766}
767
768void IOFireWireSBP2LibLogin::unsolicitedStatusNotify( IOReturn result, io_user_reference_t *args,
769																		int numArgs )
770{
771	FWLOG(( "IOFireWireSBP2LibLogin : unsolicitedStatusNotify numArgs = %d\n", numArgs ));
772
773	FWSBP2NotifyParams params;
774
775	UInt32 statusBlock[8];
776	{
777		int i;
778
779		for( i = 0; i < 8; i++ )
780		{
781			IF_ROSETTA()
782			{
783				statusBlock[i] = OSSwapInt32( (UInt32)args[3+i] );
784			}
785			else
786			{
787				statusBlock[i] = (UInt32)args[3+i];
788			}
789		}
790	}
791
792	params.refCon = (void*)fRefCon;
793	params.notificationEvent = (UInt32)args[0];
794	params.generation = (IOReturn)args[1];
795	params.length = (UInt32)args[2];
796	params.message = (FWSBP2StatusBlock*)&statusBlock;
797
798	if( fUnsolicitedStatusNotifyRoutine != NULL )
799		(fUnsolicitedStatusNotifyRoutine)( fUnsolicitedStatusNotifyRefCon, &params );
800}
801
802// statusNotify
803//
804//
805
806void IOFireWireSBP2LibLogin::staticStatusNotify( void *refcon, IOReturn result,
807													io_user_reference_t *args, int numArgs )
808{
809	((IOFireWireSBP2LibLogin*)refcon)->statusNotify( result, args, numArgs );
810}
811
812void IOFireWireSBP2LibLogin::statusNotify( IOReturn result, io_user_reference_t *args, int numArgs )
813{
814	FWLOG(( "IOFireWireSBP2LibLogin : statusNotify numArgs = %d\n", numArgs ));
815
816//	printf( "IOFireWireSBP2LibLogin : statusNotify numArgs = %d\n", numArgs );
817
818	FWSBP2NotifyParams params;
819
820	UInt32 statusBlock[8];
821	{
822		int i;
823
824		for( i = 0; i < 8; i++ )
825		{
826			IF_ROSETTA()
827			{
828				statusBlock[i] = OSSwapInt32( (UInt32)args[4+i] );
829			}
830			else
831			{
832				statusBlock[i] = (UInt32)args[4+i];
833			}
834		}
835	}
836
837#if 0
838	{
839		int i;
840
841		for( i = 0; i < 8; i++ )
842		{
843			printf( "IOFireWireSBP2LibLogin : statusNotify params[%d] 0x%08lx\n", i, statusBlock[i] );
844		}
845	}
846#endif
847
848	params.notificationEvent = (UInt32)args[0];
849	params.generation = (IOReturn)args[1];
850	params.length = (UInt32)args[2];
851	params.refCon = (void*)args[3];
852	params.message = (FWSBP2StatusBlock*)&statusBlock;
853
854#if 0
855	printf( "IOFireWireSBP2LibLogin : statusNotify args[0] 0x%08llx\n", (UInt32)args[0] );
856	printf( "IOFireWireSBP2LibLogin : statusNotify args[1] 0x%08llx\n", (IOReturn)args[1] );
857	printf( "IOFireWireSBP2LibLogin : statusNotify args[2] 0x%08llx\n", (UInt32)args[2] );
858	#if __LP64__
859		printf( "IOFireWireSBP2LibLogin : statusNotify args[3] 0x%016llx\n", (void*)args[3] );
860	#else
861		printf( "IOFireWireSBP2LibLogin : statusNotify args[3] 0x%08lx\n", (void*)args[3] );
862	#endif
863#endif
864
865	if( fStatusNotifyRoutine != NULL )
866		(fStatusNotifyRoutine)( fStatusNotifyRefCon, &params );
867}
868
869// setFetchAgentResetCallback
870//
871//
872
873void IOFireWireSBP2LibLogin::staticSetFetchAgentResetCallback( void * self, void * refCon, IOFWSBP2StatusCallback callback )
874{
875	getThis(self)->setFetchAgentResetCallback( refCon, callback );
876}
877
878void IOFireWireSBP2LibLogin::setFetchAgentResetCallback( void * refCon, IOFWSBP2StatusCallback callback )
879{
880	fFetchAgentResetCallback = callback;
881	fFetchAgentResetRefCon = refCon;
882}
883
884// submitFetchAgentReset
885//
886//
887
888IOReturn IOFireWireSBP2LibLogin::staticSubmitFetchAgentReset( void * self )
889{
890	return getThis(self)->submitFetchAgentReset();
891}
892
893IOReturn IOFireWireSBP2LibLogin::submitFetchAgentReset( void )
894{
895	IOReturn status = kIOReturnSuccess;
896
897	if( status == kIOReturnSuccess )
898	{
899		io_async_ref64_t asyncRef;
900		mach_msg_type_number_t	size = 0;
901		uint64_t	params[1];
902
903		params[0] = fLoginRef;
904
905		asyncRef[kIOAsyncCalloutFuncIndex] = (uint64_t)&IOFireWireSBP2LibLogin::staticFetchAgentResetCompletion;
906		asyncRef[kIOAsyncCalloutRefconIndex] = (uint64_t)this;
907
908		status = IOConnectCallAsyncScalarMethod( fConnection, kIOFWSBP2UserClientSubmitFetchAgentReset, fAsyncPort, asyncRef, kOSAsyncRef64Count, params, 1, NULL, &size  );
909	}
910
911	return status;
912
913}
914
915// fetchAgentResetCompletion
916//
917//
918
919void IOFireWireSBP2LibLogin::staticFetchAgentResetCompletion( void *refcon, IOReturn result, io_user_reference_t *args,
920												int numArgs )
921{
922	((IOFireWireSBP2LibLogin*)refcon)->fetchAgentResetCompletion( result, args, numArgs );
923}
924
925void IOFireWireSBP2LibLogin::fetchAgentResetCompletion( IOReturn result, io_user_reference_t *args, int numArgs )
926{
927	if( fFetchAgentResetCallback != NULL )
928		(fFetchAgentResetCallback)( fFetchAgentResetRefCon, result );
929}
930
931// setFetchAgentWriteCallback
932//
933//
934
935void IOFireWireSBP2LibLogin::staticSetFetchAgentWriteCallback( void * self, void * refCon, IOFWSBP2FetchAgentWriteCallback callback )
936{
937	getThis(self)->setFetchAgentWriteCallback( refCon, callback );
938}
939
940void IOFireWireSBP2LibLogin::setFetchAgentWriteCallback( void * refCon, IOFWSBP2FetchAgentWriteCallback callback )
941{
942	fFetchAgentWriteCallback = callback;
943	fFetchAgentWriteRefCon = refCon;
944}
945
946// fetchAgentWriteCompletion
947//
948//
949
950void IOFireWireSBP2LibLogin::staticFetchAgentWriteCompletion( void *refcon, IOReturn result, io_user_reference_t *args,
951												int numArgs )
952{
953	((IOFireWireSBP2LibLogin*)refcon)->fetchAgentWriteCompletion( result, args, numArgs );
954}
955
956void IOFireWireSBP2LibLogin::fetchAgentWriteCompletion( IOReturn result, io_user_reference_t *args, int numArgs )
957{
958	if( fFetchAgentWriteCallback != NULL )
959		(fFetchAgentWriteCallback)( fFetchAgentWriteRefCon, result, NULL );
960}
961
962// ringDoorbell
963//
964//
965
966IOReturn IOFireWireSBP2LibLogin::staticRingDoorbell( void * self )
967{
968	return getThis(self)->ringDoorbell();
969}
970
971IOReturn IOFireWireSBP2LibLogin::ringDoorbell( void )
972{
973	IOReturn status = kIOReturnSuccess;
974
975	if( status == kIOReturnSuccess )
976	{
977		uint32_t	size = 0;
978		status = IOConnectCallScalarMethod( fConnection,
979											kIOFWSBP2UserClientRingDoorbell,
980											&fLoginRef, 1,
981											NULL, &size );
982	}
983
984	return status;
985}
986
987// enableUnsolicitedStatus
988//
989//
990
991IOReturn IOFireWireSBP2LibLogin::staticEnableUnsolicitedStatus( void * self )
992{
993	return getThis(self)->enableUnsolicitedStatus();
994}
995
996IOReturn IOFireWireSBP2LibLogin::enableUnsolicitedStatus( void )
997{
998	IOReturn status = kIOReturnSuccess;
999
1000	if( status == kIOReturnSuccess )
1001	{
1002		uint32_t	size = 0;
1003		status = IOConnectCallScalarMethod( fConnection,
1004											kIOFWSBP2UserClientEnableUnsolicitedStatus,
1005											&fLoginRef, 1,
1006											NULL, &size );
1007	}
1008
1009	return status;
1010}
1011
1012// setBusyTimeoutRegisterValue
1013//
1014//
1015
1016IOReturn IOFireWireSBP2LibLogin::staticSetBusyTimeoutRegisterValue( void * self, UInt32 timeout )
1017{
1018	return getThis(self)->setBusyTimeoutRegisterValue( timeout );
1019}
1020
1021IOReturn IOFireWireSBP2LibLogin::setBusyTimeoutRegisterValue( UInt32 timeout )
1022{
1023	IOReturn status = kIOReturnSuccess;
1024
1025	if( status == kIOReturnSuccess )
1026	{
1027		uint64_t	params[2];
1028		uint32_t	size = 0;
1029
1030		params[0]	= fLoginRef;
1031		params[1] 	= timeout;
1032		status = IOConnectCallScalarMethod( fConnection,
1033											kIOFWSBP2UserClientSetBusyTimeoutRegisterValue,
1034											params, 2,
1035											NULL, &size );
1036	}
1037
1038	return status;
1039}
1040
1041// setPassword
1042//
1043//
1044
1045IOReturn IOFireWireSBP2LibLogin::staticSetPassword( void * self, void * buffer, UInt32 length )
1046{
1047	return getThis(self)->setPassword( buffer, length );
1048}
1049
1050IOReturn IOFireWireSBP2LibLogin::setPassword( void * buffer, UInt32 length )
1051{
1052	IOReturn status = kIOReturnSuccess;
1053
1054	FWLOG(( "IOFireWireSBP2LibORB : setPassword\n" ));
1055
1056	uint32_t len = 0;
1057	uint64_t params[3];
1058
1059	params[0] = fLoginRef;
1060	params[1] = (UInt64)buffer;
1061	params[2] = length;
1062
1063	status = IOConnectCallScalarMethod( fConnection,
1064										kIOFWSBP2UserClientSetPassword,
1065										params, 3, NULL, &len );
1066	return status;
1067}
1068
1069
1070// getLoginRef
1071//
1072//
1073
1074UInt32 IOFireWireSBP2LibLogin::getLoginRef( void )
1075{
1076	return fLoginRef;
1077}
1078
1079