Set MTU size in Zephyr

Hello,

I ran the throughput example ,but I found that setting the MTU size actually requires calling the bt_gatt_exchange_mtu function, which is different from sdk16.0 .

In sdk16.0 or other versions, I can set the MTU size by calling nrf_ble_gatt_att_mtu_periph_set()  and nrf_ble_gatt_att_mtu_central_set() .

Is there any way to automatically set the MTU size in Zephyr?

Best Regards,

Gray

Parents Reply
  • Hey again Grey,

    I added the bt_gatt_get_mtu functions to the exchange and discovery complete functions:

    static void exchange_func(struct bt_conn *conn, uint8_t att_err,
    			  struct bt_gatt_exchange_params *params)
    {
    	struct bt_conn_info info = {0};
    	int err;
    
    	printk("MTU exchange %s\n", att_err == 0 ? "successful" : "failed");
    	printk("MTU size is: %d\n", bt_gatt_get_mtu(conn));
    
    	err = bt_conn_get_info(conn, &info);
    	if (err) {
    		printk("Failed to get connection info %d\n", err);
    		return;
    	}
    
    	if (info.role == BT_CONN_ROLE_MASTER) {
    		instruction_print();
    		test_ready = true;
    	}
    }
    
    static void discovery_complete(struct bt_gatt_dm *dm,
    			       void *context)
    {
    	int err;
    	struct bt_throughput *throughput = context;
    
    	printk("Service discovery completed\n");
    
    	bt_gatt_dm_data_print(dm);
    	bt_throughput_handles_assign(dm, throughput);
    	bt_gatt_dm_data_release(dm);
    
    	exchange_params.func = exchange_func;
    
    	printk("MTU size is: %d\n", bt_gatt_get_mtu(default_conn));
    
    	err = bt_gatt_exchange_mtu(default_conn, &exchange_params);
    	if (err) {
    		printk("MTU exchange failed (err %d)\n", err);
    	} else {
    		printk("MTU exchange pending\n");
    	}
    }

    This was my output: 
    Connected as master
    Conn. interval is 320 units
    Service discovery completed
    MTU size is: 23
    MTU exchange pending
    MTU exchange successful
    MTU size is: 247
    I'm on NCS 1.7.1 btw.
Children
Related