Working with Bluettoth PAN on iPAD

I have requirement to create a TCP/IP connection over Bluetooth PAN profile.


Scenario 1:

Mac mini as Server and iPAD as Client

  1. Create Server.c on Mac mini, compiled and started @port 1501
  2. Turn on Blueetooth PAN on Mac mini (available from settings option)
  3. Connect iPAD through Bluetooth
  4. Create a iPAD app to run the TCP/IP client & execute
  5. Able to send data from client ( iPAD ) to server ( Mac mini ) over Bluetooth PAN


Scenario 2:

Mac mini as Client and iPAD as Server

  1. Create Client.c on Mac mini, compile and able to run @ specific ip/port
  2. Turn on Blueetooth PAN on iPAD (we don’t have any option to turn on Blueetooth PAN on iPAD like mac mini, even tried finding a code to enable Bluetooth PAN on iPAD)
  3. Connect Mac mini through Bluetooth
  4. Write a iPad app to create TCP/IP server & execute
  5. Able to send data from client (Mac mini) to server ( iPAD ) over Bluetooth PAN


But on second scenario we are struck at step 2, we don’t have option to enable BT PAN from iPAD settings, even we don’t have code available to enable it.


Please help us on this item.


Thank You in advance

Code Server.c ( runs on Mac mini Scenario 1 )

#include <stdio.h>

#include <stdlib.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <sys/wait.h>

#include <errno.h>

#include <netinet/in.h>

#include <string.h>

#include <arpa/inet.h>

#include <netdb.h>

#include <unistd.h>

#define MYPORT 1501

#define BACKLOG 5

#define MAXDATASIZE 100

int main()

{

int servSock, cliProc;

socklen_t sin_size;

char buf[MAXDATASIZE], msg[MAXDATASIZE];

struct sockaddr_in my_addr, income_addr;

my_addr.sin_family = AF_INET;

my_addr.sin_port = htons(MYPORT);

my_addr.sin_addr.s_addr = htonl(INADDR_ANY);

if ((servSock = socket(AF_INET, SOCK_STREAM, 0)) == -1)

printf("Socket Error: %d\n", errno);

else

printf("Server Socket %d created\n", servSock);

if (bind(servSock, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)

printf("Bind Error: %d\n", errno);

else

printf("Server Bind created\n");

listen(servSock, BACKLOG);

printf("Server is waitting for connection...\n");

sin_size = sizeof(struct sockaddr_in);

if ((cliProc = accept(servSock, (struct sockaddr *)&income_addr, &sin_size)) == -1)

printf("Accept Error: %d\n", errno);

else

{

printf("Server accepted connection from %s\n", inet_ntoa(income_addr.sin_addr));

}

sprintf(msg, "Welcome to Server, you addr is %s", inet_ntoa(income_addr.sin_addr));

send(cliProc, msg, strlen(msg), 0);

if (recv(cliProc, buf, MAXDATASIZE, 0) == -1)

{

printf("Recv Error: %d\n", errno);

}

else

{

printf("Server received %s from %s\n", buf, inet_ntoa(income_addr.sin_addr));

}

close(cliProc);

close(servSock);

printf("Server Sockets closed\n");

return 0;

}


Code Client.c ( runs on Mac mini Scenario 2 )



#include <stdio.h>

#include <sys/socket.h>

#include <netinet/in.h>

#include <string.h>


int main(){

int clientSocket;

char buffer[1024];

struct sockaddr_in serverAddr;

socklen_t addr_size;

char temp[] = "am client";


/---- Create the socket. The three arguments are: ----*/

/ 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */

clientSocket = socket(PF_INET, SOCK_STREAM, 0);


/---- Configure settings of the server address struct ----*/

/ Address family = Internet */

serverAddr.sin_family = AF_INET;

/ Set port number, using htons function to use proper byte order */

serverAddr.sin_port = htons(8080);


/ Set IP address to localhost */

serverAddr.sin_addr.s_addr = inet_addr("169.254.14.252");

/ Set all bits of the padding field to 0 */

memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);


/---- Connect the socket to the server using the address struct ----*/

addr_size = sizeof serverAddr;

connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);

send(clientSocket,temp,strlen(temp),0);

/---- Read the message from the server into the buffer ----*/

recv(clientSocket, buffer, 1024, 0);


/---- Print the received message ----*/

printf("Data received: %s\n",buffer);


return 0;

}