how to compare incoming number and a list of predefined numbers

LLANGE:
Add the number to the SIM PhoneBook CLIP should do the work for you…

You can decide to blacklist numbers where the text of the PB entry starts with '!' or are above index 127.

Whilst receiving a call, parse the +CLIP: line eg.
RING
+CLIP: "+123444719",145,"",0,"",0

Get the alphaId part (converted as an integer):

  • if empty then caller is 404 (unknown);
  • if below 0 (signed interger) || above 127 (unsigned) then caller is 403 (blacklisted);
  • if between 1 and 127 then200 (known);

If you managing (un)authorized callers using the text part of the phonebook entries you'll then query the phonebook using AT+CPBR= (which should take maximum 3s + the time to parse)…

int i=0;

int r=0;
char* p=strstr(buffer,"+CLIP:");
p = strtok(p,",");
while(p != NULL)
{  switch(++i)
    { case 5:
          r=atoi(strtok(p,"""));
          break;
      // 1 number, 2 type, 3 subaddress, 4 sub address type, 5 alphaId (phonebook index), 6 CLI Validity
    }
    p = strtok(NULL,",");
}
if(r>0 && r <128)Serial.println("Known and authorized CallerID");

I am also trying to get the number from SIM card with "AT+CPBF="Arduino"" and output like +CPBF: 1,"XXXXXXXXXXXXXX",255,"Arduino.

above you code is giving error 'buffer' was not declared in this scope.