LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   how to programme with the bluetooth passcode? (http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/how-to-programme-with-the-bluetooth-passcode-762905/)

feiyinziiu 10-19-2009 04:50 AM

how to programme with the bluetooth passcode?
 
Hello,

I'm programming with bluez to use the
bluetooth dongle under linux to connect to
the remote bluetooth devices.But when the
my PC run the programme,and try to connect to the bluetooth of my cellphone,it ask for passcode.and I don't know how to deal with it.after I put in passcode, the bluetooth says :connect refused.





how to programm with the passcode?



thank you!



my bluetooth test is this:



1 #include <stdio.h>
2 #include <unistd.h>
3 #include <sys/socket.h>
4 #include <bluetooth/bluetooth.h>
5 #include <bluetooth/rfcomm.h>
6 int main(int argc, char **argv)
7 {
8 struct sockaddr_rc addr = { 0 };
9 int s, status;
10 char dest[18] = "00:26:68:DB:2E:70";
11 // allocate a socket
12 s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
13 // set the connection parameters (who to connect to)
14 addr.rc_family = AF_BLUETOOTH;
15 addr.rc_channel = (uint8_t) 1;
16 str2ba( dest, &addr.rc_bdaddr );
17 // connect to server
18 status = connect(s, (struct sockaddr *)&addr, sizeof(addr));
19 printf("return\n");
20 // send a message
21 //if( status == 0 ) {
22 status = write(s, "hello!", 6);
23 //}
24 if( status < 0 ) perror("uh oh");
25 close(s);
26 return 0;
27 }
28

MS3FGX 10-20-2009 03:28 PM

So you are trying to specify the PIN in the running program, rather than using BlueZ's system-wide PIN settings?

feiyinziiu 10-20-2009 08:21 PM

Quote:

Originally Posted by MS3FGX (Post 3726345)
So you are trying to specify the PIN in the running program, rather than using BlueZ's system-wide PIN settings?

Thanks for you reply.

en,yes.Because I find that my USB bluetooth dongle cannot connect to my nokia cellphone without the passcode.
I have searched the Interner.they told me to modify the hcid.conf and pin files.I did,however,I faided to connect my cellphone.
so I want to programm with the passcode.

my hcid.conf settings are like this:

#
# HCI daemon configuration file.
#

# HCId options
options {
# Automatically initialize new devices
autoinit yes;

# Security Manager mode
# none - Security manager disabled
# auto - Use local PIN for incoming connections
# user - Always ask user for a PIN
#
security auto;

# Pairing mode
# none - Pairing disabled
# multi - Allow pairing with already paired devices
# once - Pair once and deny successive attempts
pairing multi;

# Default PIN code for incoming connections
passkey "12345";
}

# Default settings for HCI devices
device {
# Local device name
# %d - device id
# %h - host name
name "BlueZ (%d)";

# Local device class
class 0x000100;

# Default packet type
#pkt_type DH1,DM1,HV1;

# Inquiry and Page scan
iscan enable; pscan enable;

# Default link mode
# none - no specific policy
# accept - always accept incoming connections
# master - become master on incoming connections,
# deny role switch on outgoing connections
lm accept;

# Default link policy
# none - no specific policy
# rswitch - allow role switch
# hold - allow hold mode
# sniff - allow sniff mode
# park - allow park mode
lp rswitch,hold,sniff,park;
}


with those settings,I still cannot connect to my cellphone successfully.


All times are GMT -5. The time now is 12:50 PM.