ZHCU938C May 2018 – January 2021 CC3100 , CC3100MOD , CC3200 , CC3200MOD
以下是简单配置文件连接的示例代码,使用按钮方法和具有已知远程 GO 器件名称(不含 MAC)的配置文件连接,将器件配置为充当 P2P 客户端器件。
unsigned char val = 1;
unsigned char policyVal;
unsigned char my_p2p_device[33];
unsigned char *remote_p2p_device = "Remote_GO_Device_XX";
unsigned char bssidEmpty[6] = {0,0,0,0,0,0};
sl_Start(NULL, NULL, NULL);
//Set P2P as active role
sl_WlanSetMode(3/*P2P_ROLE*/);
//Set P2P client dhcp enable (assuming remote GO running DHCP server)
sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&val);
//Set Device Name
strcpy(my_p2p_device,"jacky_sl_p2p_device");
sl_NetAppSet (SL_NET_APP_DEVICE_CONFIG_ID,
NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(my_p2p_device),
(unsigned char *) my_p2p_device);
//set connection policy Auto-Connect
sl_WlanPolicySet( SL_POLICY_CONNECTION,
SL_CONNECTION_POLICY(1/*Auto*/,0/*Fast*/,
0/*OpenAP*/,0/*AnyP2P*/),
&policyVal, 0 /*PolicyValLen*/
);
//set P2P Policy - intent 0, random backoff
sl_WlanPolicySet( SL_POLICY_P2P,
SL_P2P_POLICY(SL_P2P_ROLE_CLIENT/*Intent 0 - Client*/,
SL_P2P_NEG_INITIATOR_RAND_BACKOFF/*Negotiation initiator – random backoff*/),
&policyVal,0 /*PolicyValLen*/
);
sl_WlanProfileAdd(
SL_SEC_TYPE_P2P_PBC,
remote_p2p_device,
strlen(remote_p2p_device),
bssidEmpty,
0, //unsigned long Priority,
0,//unsigned char *pKey,
0,//unsigned long KeyLen,
0//unsigned long Options)
);
sl_Stop(1);
sl_Start(NULL, NULL, NULL);