require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_NETBT_BLUETOOTH_H_)) {
    eval 'sub _NETBT_BLUETOOTH_H_ () {1;}' unless defined(&_NETBT_BLUETOOTH_H_);
    require 'sys/socket.ph';
    require 'sys/types.ph';
    eval 'sub BTPROTO_HCI () {1;}' unless defined(&BTPROTO_HCI);
    eval 'sub BTPROTO_L2CAP () {2;}' unless defined(&BTPROTO_L2CAP);
    eval 'sub BTPROTO_RFCOMM () {3;}' unless defined(&BTPROTO_RFCOMM);
    eval 'sub BTPROTO_SCO () {4;}' unless defined(&BTPROTO_SCO);
    eval 'sub BLUETOOTH_BDADDR_SIZE () {6;}' unless defined(&BLUETOOTH_BDADDR_SIZE);
    eval 'sub bdaddr_any {
        my($a) = @_;
	    eval q({ ( ($a->{b[0]}) == 0 &&  ($a->{b[1]}) == 0 &&  ($a->{b[2]}) == 0 &&  ($a->{b[3]}) == 0 &&  ($a->{b[4]}) == 0 &&  ($a->{b[5]}) == 0); });
    }' unless defined(&bdaddr_any);
    eval 'sub bdaddr_copy {
        my($d,$s) = @_;
	    eval q({  ($d->{b[0]}) =  ($s->{b[0]});  ($d->{b[1]}) =  ($s->{b[1]});  ($d->{b[2]}) =  ($s->{b[2]});  ($d->{b[3]}) =  ($s->{b[3]});  ($d->{b[4]}) =  ($s->{b[4]});  ($d->{b[5]}) =  ($s->{b[5]}); });
    }' unless defined(&bdaddr_copy);
    eval 'sub BDADDR_ANY () {(( &const  &bdaddr_t *) "\\000\\000\\000\\000\\000");}' unless defined(&BDADDR_ANY);
    if(defined(&_KERNEL)) {
	eval 'sub BLUETOOTH_DEBUG () {1;}' unless defined(&BLUETOOTH_DEBUG);
	if(defined(&BLUETOOTH_DEBUG)) {
	    eval 'sub DPRINTF () {( &fmt,  &args...)  &do {  &if ( &bluetooth_debug)  &printf("%s: " &fmt,  &__func__ ,  &args); }  &while ( 0);}' unless defined(&DPRINTF);
	    eval 'sub DPRINTFN () {( &n,  &fmt,  &args...)  &do {  &if ( &bluetooth_debug > ( &n))  &printf("%s: " &fmt,  &__func__ ,  &args); }  &while ( 0);}' unless defined(&DPRINTFN);
	    eval 'sub UNKNOWN {
	        my($value) = @_;
    		eval q( &printf(\\"%s: %s = %d unknown!\\\\n\\",  &__func__, $value, ($value)););
	    }' unless defined(&UNKNOWN);
	} else {
	    eval 'sub DPRINTF () {(...) (( &void)0);}' unless defined(&DPRINTF);
	    eval 'sub DPRINTFN () {(...) (( &void)0);}' unless defined(&DPRINTFN);
	    eval 'sub UNKNOWN {
	        my($x) = @_;
    		eval q((( &void)0));
	    }' unless defined(&UNKNOWN);
	}
	if(defined(&BLUETOOTH_DEBUG)) {
	    eval 'sub mutex_enter {
	        my($mtx) = @_;
    		eval q( &do {  &DPRINTFN(1, \\"mtx_enter(\\"  &__STRING($mtx) \\") in %d\\\\n\\",  &curproc ?  ($curproc->{p_pid}) : 0);  &mtx_enter(($mtx)); }  &while ( 0));
	    }' unless defined(&mutex_enter);
	    eval 'sub mutex_exit {
	        my($mtx) = @_;
    		eval q( &do {  &DPRINTFN(1, \\"mtx_leave(\\"  &__STRING($mtx) \\") in %d\\\\n\\",  &curproc ?  ($curproc->{p_pid}) : 0);  &mtx_leave(($mtx)); }  &while ( 0));
	    }' unless defined(&mutex_exit);
	} else {
	    eval 'sub mutex_enter () { &mtx_enter;}' unless defined(&mutex_enter);
	    eval 'sub mutex_exit () { &mtx_leave;}' unless defined(&mutex_exit);
	}
    }
}
1;
