Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Handle bluetooth pairing code

Handle bluetooth pairing code

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++wpfwcfsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vijay Rajanna
    wrote on last edited by
    #1

    Hi, I'm using windows 7 pc, and trying to write a Bluetooth server app. My requirement is to pair my Mobile (Nokia -N8) with my server app, and then exchange data using a service class. ISSUE: The issue I'm facing is, on running server on my PC, the server waits for connection request from phone. But phone is asking me to enter a pass code, But i don't know how to handle this passcode issue at server side. and establish the connection. The connection always fails with a message that no response from server. Here is my server code, which I'm running on my win 7 PC. // Bluetooth.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #pragma comment(lib, "Ws2_32.lib") int _tmain(int argc, _TCHAR* argv[]) { //---------------------- // Initialize Winsock. WSADATA wsaData; int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != NO_ERROR) { wprintf(L"WSAStartup failed with error: %ld\n", iResult); return 1; } //---------------------- // Create a SOCKET for listening for // incoming connection requests. SOCKET ListenSocket; ListenSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); if (ListenSocket == INVALID_SOCKET) { wprintf(L"socket failed with error: %ld\n", WSAGetLastError()); WSACleanup(); return 1; } //---------------------- // The sockaddr_in structure specifies the address family, // IP address, and port for the socket that is being bound. SOCKADDR_BTH blthsocket; memset(&blthsocket,0,sizeof(SOCKADDR_BTH)); blthsocket.addressFamily = AF_BTH; blthsocket.btAddr = 0; blthsocket.serviceClassId = GUID_NULL; blthsocket.port = BT_PORT_ANY ; wprintf(L"============ Before Bind =============\n"); wprintf(L"blthsocket.btAddr = %d \n",blthsocket.btAddr); wprintf(L"blthsocket.port = %d \n",blthsocket.port); if (bind(ListenSocket,(SOCKADDR *) & blthsocket, sizeof (blthsocket)) == SOCKET_ERROR) { wprintf(L"bind failed with error: %ld\n", WSAGetLastError()); closesocket(ListenSocket); WSACleanup(); return 1; } wprintf(L"Binding is complete\n"); wprintf(L"\n\n============ After Bind =============\n"); int len = sizeof(blthsocket); if (0 == getsockname (ListenSocket, (sockaddr*)&blthsocket, &len)) { wprintf (L"Local Bluetooth device is %04x%08x \nServer channel = %d\n", GET_NAP(blthsocket.btAddr), GET_SA

    _ 1 Reply Last reply
    0
    • V Vijay Rajanna

      Hi, I'm using windows 7 pc, and trying to write a Bluetooth server app. My requirement is to pair my Mobile (Nokia -N8) with my server app, and then exchange data using a service class. ISSUE: The issue I'm facing is, on running server on my PC, the server waits for connection request from phone. But phone is asking me to enter a pass code, But i don't know how to handle this passcode issue at server side. and establish the connection. The connection always fails with a message that no response from server. Here is my server code, which I'm running on my win 7 PC. // Bluetooth.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #pragma comment(lib, "Ws2_32.lib") int _tmain(int argc, _TCHAR* argv[]) { //---------------------- // Initialize Winsock. WSADATA wsaData; int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != NO_ERROR) { wprintf(L"WSAStartup failed with error: %ld\n", iResult); return 1; } //---------------------- // Create a SOCKET for listening for // incoming connection requests. SOCKET ListenSocket; ListenSocket = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); if (ListenSocket == INVALID_SOCKET) { wprintf(L"socket failed with error: %ld\n", WSAGetLastError()); WSACleanup(); return 1; } //---------------------- // The sockaddr_in structure specifies the address family, // IP address, and port for the socket that is being bound. SOCKADDR_BTH blthsocket; memset(&blthsocket,0,sizeof(SOCKADDR_BTH)); blthsocket.addressFamily = AF_BTH; blthsocket.btAddr = 0; blthsocket.serviceClassId = GUID_NULL; blthsocket.port = BT_PORT_ANY ; wprintf(L"============ Before Bind =============\n"); wprintf(L"blthsocket.btAddr = %d \n",blthsocket.btAddr); wprintf(L"blthsocket.port = %d \n",blthsocket.port); if (bind(ListenSocket,(SOCKADDR *) & blthsocket, sizeof (blthsocket)) == SOCKET_ERROR) { wprintf(L"bind failed with error: %ld\n", WSAGetLastError()); closesocket(ListenSocket); WSACleanup(); return 1; } wprintf(L"Binding is complete\n"); wprintf(L"\n\n============ After Bind =============\n"); int len = sizeof(blthsocket); if (0 == getsockname (ListenSocket, (sockaddr*)&blthsocket, &len)) { wprintf (L"Local Bluetooth device is %04x%08x \nServer channel = %d\n", GET_NAP(blthsocket.btAddr), GET_SA

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Windows has several bluetooth APIs that you can use. BluetoothAuthenticateDevice is the API to send authentication code to the bluetooth device.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups