1

I'm trying to edit the options of routers ssid using libuci. I can read properly but not getting how to edit. With the reference of below link i can read but how to edit(like if i want to change network.lan.proto).

How to find out if the eth0 mode is static or dhcp?

Community
  • 1
  • 1
user2902947
  • 17
  • 1
  • 3

3 Answers3

4

If you want to use the C API for UCI, you can use the following code:

#include <uci.h>

void main()
{
   char path[]="network.lan.proto";
   char buffer[80];
   struct  uci_ptr ptr;
   struct  uci_context *c = uci_alloc_context();

   if(!c) return;

   if ((uci_lookup_ptr(c, &ptr, path, true) != UCI_OK) ||
         (ptr.o==NULL || ptr.o->v.string==NULL)) 
   { 
     uci_free_context(c);
     return;
   }

   if(ptr.flags & UCI_LOOKUP_COMPLETE)
      strcpy(buffer, ptr.o->v.string);

   printf("%s\n", buffer);

   // setting UCI values
   // -----------------------------------------------------------
   // this will set the value to 1234
   ptr.value = "1234";
   // commit your changes to make sure that UCI values are saved
   if (uci_commit(c, &ptr.p, false) != UCI_OK)
   {
      uci_free_context(c);
      uci_perror(c,"UCI Error");
      return;
   }

   uci_free_context(c);
}

Reference is from this post: OpenWrt LibUbi implementation

Community
  • 1
  • 1
  • 1
    need to add uciset before commit .. //// if ((uci_set(c, &ptr) != UCI_OK) || (ptr.o == NULL || ptr.o->v.string == NULL )) { uci_free_context(c); return; } – zyanlu Aug 10 '17 at 04:47
1

There's a lot of documentation at the openwrt wiki:

http://wiki.openwrt.org/doc/uci

To change network.lan.proto from the command line you can use:

uci set network.lan.proto=dhcp

oh and then you'll want to commit the changes and restart the network:

uci commit network /etc/init.d/network restart

urban_raccoons
  • 3,499
  • 1
  • 22
  • 33
-1

The network configuration is located in /etc/config/network. Here is an example of a configuration you can use:

config wifi-iface
    option 'device'     'radio0'
    option 'mode'       'sta'
    option 'ssid'       'Some Wireless Network'
    option 'encryption' 'psk2'
    option 'key'        '12345678'
    option 'network'    'wwan'

You can find more documentation here: OpenWRT network config

Paktwis Homayun
  • 300
  • 3
  • 17